An expression is a snippet of AppleScript code that has a value. Expressions are evaluated every time the script pauses. This includes the point where the script completes. Expressions are likely to be most useful to you when paused during debugging. However, you can create and edit expressions at any time. Expressions are a feature of a script, and are saved when you save a compiled script.
Important: An expression may refer to local variables — but local variables must be explicitly declared local (with a local
statement), or the expression won’t be able to “see” them, and will report that the variable is undefined.
Expressions are created, edited, and displayed in the expressions pane, which is in the same tab as the result pane and the variables pane. To see the expressions pane:
Choose View > Result & Variables Tab.
Or, click Result & Variables in the toolbar.
To create an expression:
Click the + button in the expressions pane.
Or, choose Script > New Expression.
Or, select within a script and choose Script > Copy To Expressions.
To edit an expression:
To force re-evaluation of an expression:
To remove an expression:
Select it and click the - button in the expressions pane.
Or, Control-click it and choose Delete from the contextual menu.
Or, choose Script > Clear All Expressions (removes all expressions).
The expressions pane is similar to the variables pane:
An expression whose value has changed since the last pause is shown in red.
An expression is re-evaluated when you select a different stack frame in the call stack. The expression might refer to a local variable, and local variable names can have different meanings in different stack frames.
The expressions pane is an outliner, with all that this entails.
Note: Evaluating an expression is like running a little one-line script, and even a little one-line script can do powerful things. An expression that changes a variable’s value, or calls a handler in your script, can be a valid expression and therefore can have side-effects each time it is evaluated.