home *** CD-ROM | disk | FTP | other *** search
-
- # make alias list to pass to AEBuild
- proc makeAlis {name} {
- return "\[alis(╟[coerce TEXT $name -x alis]╚)\]"
- }
-
- proc makeAlises {args} {
- set str "\["
- set sep ""
- foreach name $args {
- append str "${sep}alis(╟[coerce TEXT $name -x alis]╚)"
- set sep ","
- }
- append str "\]"
- return $str
- }
-
- # Queued replies are passed through AEPrint and then to this routine.
- proc handleReply {rep} {
- global ALPHA lastReply
- # switchTo $ALPHA
- set lastReply $rep
- }
-
- # Return an object record specifying the desired think project file.
- proc fileObject {name} {
- join [concat {obj\{want:type('SFIL'), from:'null'(), form:'name', seld:╥} [file tail $name] {╙\}}] ""
- }
-
- proc sendOpenEvent {filler appname fname} {
- if {$filler == "noReply"} {
- AEBuild $appname aevt odoc "----" [makeAlis $fname]
- } else {
- AEBuild -r $appname aevt odoc "----" [makeAlis $fname]
- }
- }
-
- # Send multiple open events
- proc sendOpenEvents {appname args} {
- AEBuild -r $appname aevt odoc "----" [eval makeAlises $args]
- }
-
- #================================================================================
- # General Apple Event handling routines
- #
- # (written by Tom Pollard for use in the MacPerl package)
- #================================================================================
-
- # Quit an application.
- proc sendQuitEvent {appname} {
- AEBuild $appname "aevt" "quit"
- }
-
- # Close one of an application's windows, designated by number.
- proc sendCloseWinNum {appname num} {
- AEBuild $appname "core" "clos" "----" [AEWinByPos $num]
- }
-
- # Close one of an application's windows, designated by name.
- proc sendCloseWinName {appname name} {
- AEBuild $appname "core" "clos" "----" [AEWinByName $name]
- }
-
- # Obtain the number of lines in one of an application's
- # windows, designated by name.
- proc sendCountLines {appname name} {
- set winObj [AEWinByName $name]
- set res [AEBuild -r $appname "core" "cnte" "----" $winObj kocl type('clin')]
- if {[regexp {:(.*)\}} $res allofit nlines]} {
- return $nlines
- } else {
- return 0
- }
- }
-
- # Get a selected range of lines from one of an application's
- # windows, designated by name. If $last is missing, then a single
- # line is returned; if both $first and $last are missing, then
- # the complete window contents are returned.
- proc sendGetText {appname name {first {missing}} {last {missing}}} {
- global ALPHA
- set winObj [AEWinByName $name]
- if {$first != "missing"} {
- if {$last != "missing"} {
- set rangDesc [AELineRange $first $last]
- } else {
- set rangDesc [AEAbsPos $first]
- }
- set objDesc "obj{want:type('clin'), from:$winObj, $rangDesc }"
- } else {
- set objDesc "obj{want:type('ctxt'), from:$winObj, form:'indx', seld:abso('all') }"
- }
- set res [AEBuild -r $appname "core" "getd" "----" $objDesc]
- if {![regexp {╥.*╙} $res text]} { set text {} }
- return [string trim $text {╥╙}]
- }
-
- # Set a selected range of lines in one of an application's
- # windows, designated by name. If $last is missing, then a single
- # line is changed; if both $first and $last are missing, then
- # the complete window contents are replaced by the new text.
- proc sendSetText {appname name text {first {missing}} {last {missing}}} {
- set winObj [AEWinByName $name]
- if {$first != "missing"} {
- if {$last != "missing"} {
- set rangDesc [AELineRange $first $last]
- } else {
- set rangDesc [AEAbsPos $first]
- }
- set objDesc "obj{want:type('clin'), from:$winObj, $rangDesc }"
- } else {
- set objDesc "obj{want:type('ctxt'), from:$winObj, form:'indx', seld:abso('all') }"
- }
- set res [AEBuild -r $appname "core" "setd" "----" $objDesc "data" [curlyq $text]]
- if {![regexp {╥.*╙} $res text]} { set text {} }
- return [string trim $text {╥╙}]
- }
-
- ################################################################################
- # Utility functions for constructing AppleEvent descriptors for AEBuild
- ################################################################################
-
- proc AEFilename {name} {
- return "obj{want:type('file'), from:'null'(), [AEName $name] } "
- }
-
- proc AEWinByName {name} {
- return "obj{want:type('cwin'), from:'null'(), [AEName $name] } "
- }
-
- proc AEWinByPos {absPos} {
- return "obj{want:type('cwin'), from:'null'(), [AEAbsPos $absPos] } "
- }
-
- proc AELineRange {absPos1 absPos2} {
- set lineObj1 "obj{ want:type('clin'), from:'ccnt'(), [AEAbsPos $absPos1] }"
- set lineObj2 "obj{ want:type('clin'), from:'ccnt'(), [AEAbsPos $absPos2] }"
- return "form:'rang', seld:rang{star:$lineObj1, stop:$lineObj2 } "
- }
-
- proc AEAbsPos {posName} {
- #
- # Use '1' or 'first' to specify first position
- # and '-1' or 'last' to specify last position.
- #
- if {$posName == "first"} {
- set posName 1
- } elseif {$posName == "last"} {
- set posName -1
- }
- if {$posName >= -1} {
- return "form:indx, seld:long($posName)"
- } else {
- error "AEAbsPos: bad argument"
- }
- }
-
- proc AEName {name} {
- return "form:'name', seld:[curlyq $name]"
- }
-
- proc curlyq {str} {
- return "\╥$str\╙"
- }
-
- ################################################################################
-