Running Other Scripts and Handlers

Scripts and handlers outside of your initial handler can be run as commands or functions, depending on the scenario. The simplest way to run another script is to use the name of that script as a command, along with any needed parameters. For example, the following command will run the tellMeMore script:

tellMeMore 1,2,3

A specific handler within a script can be run by using the script name, a dot or apostrophe-s, and the handler name, followed by any parameters:

tellMeMore's elucidation "terse",5

utilities.insertCommas @myNumber,3

For more complex situations, the following commands and functions may be useful.

Run Command

Behavior: Calls the scriptName script, or the handlerName handler of that script, as a command. HandlerName is usually just the simple name of a handler without quotes, but may also be given as a quoted literal, or as an expression in parentheses to construct the handler name at run time.

The run command can be used to run a specified script when a simple command as shown above won't work, such as when a full pathname is needed or the script's name contains spaces or other special characters, or when the name of the script to be run is in a variable. The following command will run the script’s initial handler:

run "/tmp/"

Parameters may be passed:

run "common/startup" 1200,true,"salvador"

A specific handler other than the script’s initial handler may be called, using 's:

run "common/finance" 's amortize 143000,6.75,360

The run command may be used with any object, not just a script file:

run account's accrueInterest 30, 4.125

The preceding example is equivalent to:

send accrueInterest 30, 4.125 to account

Although the run command provides similar functionality to that of the send command, it offers an alternative syntax for running a script, and also gives you the ability to run the initial handler of a script, which the send command does not provide. In addition, the run command runs the script’s initial handler directly, without calling front scripts, back scripts, or helpers.


run scriptName {,} {parameters}

run scriptName 's handlerName {parameters}

Run Function

Behavior: Calls the initial handler of a script or other object explicitly as a function. This also allows calling a script whose name is generated dynamically at runtime. The run function needs to be called in a way that sends the run message to the target object, such as using dot notation.


{the} run of object {with parameters}


set doubler to (script:"return 2*param(1)")

put -- 24

get ("test" & testNumber).run(value1, value2)

-- call script dynamically

Do Command

Behavior: The do command evaluates expression as one or more SenseTalk statements and executes those statements as though they were part of the current handler. This means that the statements contained in expression can refer to, use, and modify any local variables of the handler (unless the evaluationContext global property is set to Global or Universal, in which case undeclared variables will be treated as global or universal rather than local variables).

Using the do command to execute some code is slower than including the same statements directly in your script, because the SenseTalk compiler is called to compile the code each time before it is executed. The impact on performance is especially significant if the do command will be executed many times, such as inside a repeat loop.


do expression


do "put total into quarter" & currentQtrNumber


do customCleanupCode

Do AppleScript Command, DoAppleScript Function

Behavior: Executes one or more statements written in the AppleScript scripting language that are contained in a variable or generated by your script at runtime. Any final value or error will be available in the result.


do AppleScript expression

do expression as AppleScript

get doAppleScript(expression)


do acquireDataScript as AppleScript

put "eggPlant" into app

-- name of the app we want to leave showing

do AppleScript merge of {{

tell application "Finder"


set visible of every process whose name is not "[[app]]" to false

end tell


put doAppleScript(merge("get [[A]] + [[B]]")) into sumDoneTheHardWay

Tech Talk

The do AppleScript command evaluates expression as AppleScript statements and executes those statements by calling the AppleScript interpreter. Values can be passed in at any point within the AppleScript code by enclosing local SenseTalk variable names and expressions in double square brackets [[ ]] within the code and using the merge function to insert their values before running the AppleScript.

When run using the doAppleScript function, the final value of the AppleScript expression will be the value returned by the function. Any errors will be returned as an exception object in the result. When do AppleScript is run as a command, the result will contain either an exception object or the final value of the expression.

The AppleScript code is run on the local machine. To send messages to another machine using this mechanism, the other machine will need to have remote events turned on in the Sharing panel of the System Preferences, and your AppleScript code will need to send commands to that machine using a tell statement looking something like this:

tell application "AppName" of machine "eppc://"

Consult an AppleScript reference for more details.

Send Command

Behavior: Sends a message to another object. Message is an expression which is evaluated as text. The message sent may include parameters, either within the message string (as in the calculateLoan example) or separately (as in the accrueInterest example). If an object is not specified, the message is sent to the object me (that is, the object containing the script).


send message {to object}

send message parameters {to object}


send "Hello" to newObject


send "calculateLoan 10,9,5000" to "Loan"


send accrueInterest 30, 4.625 to account

Target Function

Behavior: Returns the long ID of the object to which the current message was sent. Useful in a handler farther down the message passing path when you need to know what the original target of the message was.


the target


As of SenseTalk version 1.1, using the syntax the target accesses the target object directly. The target() syntax calls a function which (if not overridden by another script in the message path) will return the long ID of the target object. This will function equivalently for most purposes, although it may be slightly less efficient in some cases.


if the target is not me then ...

[ ] (Square Bracket Messaging)

Behavior: Use square brackets to send a function-type message to a specific object. The square bracket syntax can be used by itself as a statement, or like a function call as part of an expression. In both cases, however, the message it sends is a function message, so it must be handled by a to or function handler (not an on handler).


[ object functionMessage ]

[ object functionMessage: parameters]


[currentLoan computeInterest:10,9,5000]


answer "The result is: " & [calculator getResult]


This topic was last updated on July 02, 2020, at 02:51:54 PM.

Eggplant icon | Documentation Home | User Forums | Support | Copyright © 2020 Eggplant