sl@0: sl@0: sl@0: sl@0: sl@0: tclOSAScript -- OSA sl@0: sl@0: sl@0: sl@0: sl@0: sl@0:

TclAppleScript Extension Command

sl@0: sl@0:

NAME

sl@0:
sl@0:
sl@0: AppleScript - Communicate with the AppleScript OSA component to run sl@0: AppleScripts from Tcl. sl@0:
sl@0:

SYNOPSIS

sl@0:
sl@0: AppleScript compile ?-flag value? scriptData1 sl@0: ?ScriptData2 ...?componentName sl@0:
sl@0: AppleScript decompile scriptName sl@0:
sl@0: AppleScript delete what scriptName sl@0:
sl@0: AppleScript execute ?flags value? scriptData1 sl@0: ?scriptData2 ...? sl@0:
sl@0: AppleScript info what sl@0:
sl@0: AppleScript load ?flag value? fileName sl@0:
sl@0: AppleScript run ?flag value? sl@0: scriptName sl@0:
sl@0: AppleScript store ?flag value? scriptName fileName sl@0:
sl@0:
sl@0: sl@0:

DESCRIPTION

sl@0:
sl@0:
sl@0: sl@0: sl@0: This command is used to communicate with the AppleScript OSA component. sl@0: You can compile scripts, run compiled scripts, execute script data (i.e. compile and run at a sl@0: blow). You can get script data from a compiled script (decompile it), and you can load a compiled script from the scpt resource of a sl@0: file, or store one to a scpt resource. You can sl@0: also get info on the currently available scripts sl@0: and contexts. It has the general form sl@0: sl@0:
sl@0:
sl@0:

sl@0: AppleScript option ?arg arg ...? sl@0:

sl@0:

sl@0: The possible sub-commands are: sl@0:

sl@0:

sl@0:
sl@0: AppleScript compile ?-flag value? scriptData1 sl@0: ?ScriptData2 ...? sl@0:
sl@0: sl@0:
sl@0: The scriptData sl@0: elements are concatenated (with a space between each), and sl@0: sent to AppleScript sl@0: for compilation. There is no limitation on the size of sl@0: the scriptData, beyond the available memory of the Wish interpreter. sl@0:

sl@0: If the compilation is successful, then the command will return a token sl@0: that you can pass to the "run" subcommand. If the sl@0: compilation fails, then the return value will be the error message from sl@0: AppleScript, and the pertinent line of code, with an "_" to indicate sl@0: the place where it thinks the error occured. sl@0:

sl@0: The sl@0: compilation is controlled by flag value pairs. The available flags sl@0: are: sl@0:

sl@0:

sl@0:
sl@0: -augment Boolean sl@0:
sl@0: To be used in concert with the -context flag. sl@0: If augment is yes, sl@0: then the scriptData augments the handlers and data already in the sl@0: script context. If augment is no, then the scriptData replaces the sl@0: data and handlers already in the context. The default is yes. sl@0:

sl@0: sl@0: sl@0:

sl@0: -context Boolean sl@0:
sl@0: This flag causes the code given in the scriptData to be compiled sl@0: into a "context". In AppleScript, this is the equivalent of creating an Tcl sl@0: Namespace. The command in this case returns the name of the context as sl@0: the its result, rather than a compiled script name. sl@0:

sl@0: You can store data and procedures (aka sl@0: handlers) in a script context. Then later, you can sl@0: run other scripts in this context, and they will see all the data and sl@0: handlers that were set up with this command. You do this by passing the sl@0: name of this context to the -context flag of the run or execute subcommands. sl@0:

sl@0: Unlike the straight compile command, the code compiled into a sl@0: script context is run immediatly, when it is compiled, to set up the context. sl@0:

sl@0:

sl@0: -name string sl@0:

sl@0: Use string as the name of the script or script context. If there is sl@0: already a script sl@0: of this name, it will be discarded. The same is true with script sl@0: contexts, unless the -augment flag is true. If no name is provided, then a sl@0: unique name will be created for you. sl@0:
sl@0:

sl@0: -parent contextName sl@0:

sl@0: This flag is also to be used in conjunction with the -context flag. sl@0: contextName must be the name of a compiled script context. Then sl@0: the new script context will inherit the data and handlers from the sl@0: parent context. sl@0:
sl@0:

sl@0:

sl@0: AppleScript decompile scriptName sl@0:
sl@0:
sl@0: This decompiles the script data compiled into the script scriptName, sl@0: and returns the source code. sl@0:

sl@0:

sl@0: AppleScript delete what scriptName sl@0:
sl@0:
sl@0: This deletes contexts or script data. The allowed values for "what" are: sl@0:

sl@0:

sl@0:
sl@0:

sl@0: context sl@0:

sl@0: This deletes the context scriptName, sl@0: and frees up all the resources associated with it. sl@0:
sl@0:

sl@0: script sl@0:

sl@0: This deletes the script data compiled into the script scriptName, sl@0: and frees up all the resources associated with it. sl@0:
sl@0:

sl@0:

sl@0: AppleScript execute ?flags value? scriptData1 sl@0: ?scriptData2 ...? sl@0:
sl@0:
sl@0: This compiles and runs the script in scriptData (concatenating first), and sl@0: returns the results of the script execution. It is the same as doing sl@0: compile and then run, except that the compiled script is sl@0: immediately discarded. sl@0:

sl@0:

sl@0: AppleScript info what sl@0:
sl@0: This gives info on the connection. The allowed values for "what" are: sl@0:

sl@0:

sl@0:
sl@0:

sl@0: contexts ?pattern? sl@0:

sl@0: This gives the list of the script contexts that have been. sl@0: If pattern is given, it only reports the contexts sl@0: that match this pattern. sl@0:
sl@0: sl@0:

sl@0: scripts ?pattern? sl@0:

sl@0: This returns a list of the scripts that have been compiled in the sl@0: current connection. If pattern is given, it only reports the sl@0: script names that match this pattern. sl@0:
sl@0:

sl@0:

sl@0: AppleScript load ?flag value? fileName sl@0:
sl@0: This loads compiled script data from a resource of type 'scpt' in the sl@0: file fileName, and returns a token for the script data. As with the sl@0: compile command, the script is not actually executed. Note that all sl@0: scripts compiled with Apple's "Script Editor" are stored as script sl@0: contexts. However, unlike with the "compile -context" command, the load sl@0: command does not run these scripts automatically. If you want to set up sl@0: the handlers contained in the loaded script, you must run it manually. sl@0:

sl@0: load takes the following flags: sl@0:

sl@0:

sl@0:
sl@0: -rsrcname string sl@0:
sl@0: load a named resource of type 'scpt' using the rsrcname sl@0: flag. sl@0:
sl@0:

sl@0: -rsrcid integer sl@0:

sl@0: load a resource by number with the rsrcid flag. sl@0:
sl@0:
sl@0:

sl@0: If neither the rsrcname nor the rsrcid flag is provided, then the load sl@0: command defaults to -rsrcid = 128. This is the resource in which sl@0: Apple's Script Editor puts the script data when it writes out a sl@0: compiled script. sl@0:

sl@0:

sl@0: AppleScript run ?flag value? scriptName sl@0:
sl@0: This runs the script which was previously compiled into scriptName. If the script sl@0: runs successfully, the command returns the return value for this command, sl@0: coerced to a text string. sl@0: If there is an error in sl@0: the script execution, then it returns the error result from the sl@0: scripting component. It accepts the following flag: sl@0: sl@0:
sl@0:
sl@0:

sl@0: -context contextName sl@0:

sl@0: contextName must be a context created by a previous call to compile with sl@0: the -context flag set. This flag causes the code given in the sl@0: scriptData to be run in this "context". It will see all the data and sl@0: handlers that were set up previously. sl@0: sl@0:
sl@0:

sl@0:

sl@0: AppleScript store ?flag value? scriptName fileName sl@0:
sl@0: This stores a compiled script or script context into a resource of type 'scpt' in the sl@0: file fileName. sl@0:

sl@0: store takes the following flags: sl@0:

sl@0:

sl@0:
sl@0: -rsrcname string sl@0:
sl@0: store to a named resource of type 'scpt' using the rsrcname sl@0: flag. sl@0:
sl@0:

sl@0: -rsrcid integer sl@0:

sl@0: store to a numbered resource with the rsrcid flag. sl@0:
sl@0:

sl@0:

sl@0: If neither the rsrcname nor the rsrcid flag is provided, then the load sl@0: command defaults to -rsrcid = 128. Apple's Script Editor can read in files written by sl@0: tclOSAScript with this setting of the -rsrcid flag. sl@0:
sl@0:
sl@0:

Notes:

sl@0: sl@0: The AppleScript command is a stopgap command to fill the place of exec sl@0: on the Mac. It is not a supported command, and will likely change sl@0: as we broaden it to allow communication with other OSA languages. sl@0:

See Also:

sl@0: sl@0: sl@0: sl@0: sl@0: