The [applescript] command.

Introduction

The applescript command lets you execute AppleScript code from a file or from a text string. AppleScript is a scripting language developed by Apple to do inter-application communication (IAC) between scriptable applications.

Synopsis

The formal syntax of the [applescript] command is:
applescript subcommand ?options?
The possible subcommands are described below. Depending on the subcommand, some options may be specified.

Applescript subcommands

The [decompile] subcommand

This subcommand returns the script source for an AppleScript file. The complete syntax is:
applescript decompile file
The file argument is the path of an AppleScript file. The script file can be in either text or compiled form. Note that a script may not have its source code available although it is executable. In this case, the command would fail.

The [execute] subcommand

This subcommand executes an AppleScript script, compiling it first. The complete syntax is:
applescript execute script
The command returns the results of the script execution. If it fails to compile or to execute the script, an error occurs.

The [run] subcommand

This subcommand executes an AppleScript file. The complete syntax is:
applescript run file
The file argument is the path of an AppleScript file. The script file can be in either text or compiled form. If the script runs successfully, the command returns the result of the execution. If it fails to execute the file, an error occurs.

Return value

The applescript command does its best to return the result (if any) of script execution in a form that is easy to handle by Tcl.
If the result descriptor obtained internally can be coerced to a string or a list of strings, then the command's result will be a Tcl string or a Tcl list respectively. Otherwise, the result is a Tcl dictionary whose keys are the descriptor's keywords (four-character codes): the corresponding values can be a Tcl string, a Tcl list or, as a last resort, a string in aegizmo format (a format that is suitable for use with the TclAE extension). Any data structures that cannot be identified are displayed as hexadecimal data.

Examples

The following example asks the Finder to open the Music folder:
set script "tell application \"Finder\"
    activate
    open folder \"Music\" of home
end tell"
applescript execute $script
Here is an example of use with a script that asks the Mail application the number of messages received. The return value in that case would be a number:
set script "tell application \"Mail\"
    count messages of inbox
end tell"
applescript execute $script
The next script will return a Tcl list:
set script "tell application \"Mail\"
    name of every account
end tell"
applescript execute $script
Here is an example of a script returning a dictionary:
set script "tell application \"Mail\"
    properties of account 1
end tell"
applescript execute $script


Last updated 2020-05-27 14:28:48