Class AppleScript
Properties
Optionallast Error
If a function fails, this property will contain the last error as a string message, otherwise it will be undefined.
Optionallast Result
If a the AppleScript subroutine called returns a value and it can be converted to a JavaScript object, it will be stored here. Most basic data types (string, date, numbers), as well as list and records containing those data types, can be returned.
Methods
execute
Compiles and executes the AppleScript code, calling the subroutine passed with the arguments.
Parameters
- subroutine: string
The name of a subroutine in the AppleScript to call. Subroutines are defined using
on subroutineName()syntax in the AppleScript. - arguments: object[]
An array of arguments to pass to the subroutine. Most basic Javascript data types, and objects and arrays of those data types, can be passed and will be translated to the proper AppleScript types.
Returns boolean
trueif the AppleScript was compiled and executed without error,falseif not. Iffalse, thelastErrorproperty will contain details regarding the error.- subroutine: string
Staticcreate
Convenience method to create an AppleScript object.
Parameters
- script: string
A string containing the AppleScript code. This code will be compiled and executed when the
executefunction is called.
Returns AppleScript
- script: string

AppleScript objects can be used to execute AppleScripts. It is highly recommended AppleScripts be developed and tested in Apple's Script Editor or similar AppleScript editor, and loaded in Drafts when completed.
Example
Note: When executed, AppleScripts are saved to temporary files in the Drafts' script directory at
~/Library/Application Scripts/com.agiletortoise.Drafts-OSXand run. The first time a script is executed, the user will be asked to grant permissions to the script directory.