This file documents version 2.2 of the TclAppleScript extension.

TclAppleScript Extension

The TclAppleScript Extension defines an [AppleScript] command which lets you execute AppleScript code from Tcl.

NAME

AppleScript - Communicate with the AppleScript OSA component to run AppleScripts from Tcl.

SYNOPSIS

The AppleScript command is used to execute AppleScript code from Tcl. You can either run compiled scripts, or execute script data in-line. You can also decompile a compiled script.
The general form of the AppleScript command is:
AppleScript subcommand ?options?
The possible subcommands are described below. Depending on the subcommand, various options can be additionally specified.

DESCRIPTION

The [decompile] subcommand

This subcommand decompiles a script. It has the following syntax:
    AppleScript decompile scriptName
The scriptName argument is the path to the script file. It can be any script compiled with Apple's AppleScript Editor as a simple script, an application or a script bundle. In case of success, the command returns the source code of the script. Note that if the script was compiled with the kOSAModePreventGetSource mode flag, the command will fail to get the source.

The [execute] subcommand

This subcommand executes a script. It has the following syntax:
    AppleScript execute scriptData
The command compiles and runs the script in the scriptData argument (concatenating first) in-line, and returns the results of the script execution

The [run] subcommand

This subcommand runs an external AppleScript file. The syntax is:
    AppleScript run scriptName
The scriptName argument is the path to the script file. If the script runs successfully, the command returns the return value for this command, coerced to a text string. If there is an error in the script execution, then it returns the error result from the scripting component.

Notes

The AppleScript Tcl command defined by the Tclapplescript extension dates back to the days of the Classic MacOS, and was originally designed as a stopgap command to fill the place of exec on the old Classic MacOS. Much of its original code and syntax are now obsolete, and its public API has been updated to support a simpler purpose, to allow execution of AppleScript code either in-line in a Tcl script, or from an external AppleScript file.

Examples

Executing a script in-line

    AppleScript execute {
        tell app "Finder"
        get name of every disk
        end tell
    }

Running an external script file

Save the above code to a file called "Test.applescript" (from any text editor) or "Test.scpt" (from Apple's AppleScript Editor tool) and execute as follows:
    AppleScript run "Test.applescript"