Language Guide
CHAPTER 6
Expressions
150 Variables
3. Click the Run button in the Script Editor window.
This causes AppleScript to evaluate the expression.
4. Choose Show Result from the Controls menu.
The result window displays the result of the evaluation, 7.
Variables 6
A variable is a named container in which to store a value. When AppleScript
encounters a variable in a statement, it evaluates the variable by getting its
value. Variables are contained in a script, not in an application, and their values
are normally lost when you close the script that contains them. If you need to
keep track of variable values that are persistent even after you close a script or
shut down your computer, use properties instead of variables. See “Script
Properties,” which begins on page 156, for more information.
Unlike variables in many other programming languages, AppleScript variables
can hold values of any class. For example, you can use the following sequence
of assignment statements to set x to a string value, an integer value, and finally
a Boolean value:
set x to "Title"
set x to 12
set x to True
The name of a variable is a series of characters, called an identifier, that you
specify when you create the variable.
Creating Variables 6
To create a variable in AppleScript, assign it a value. There are two commands
for doing this:
■ Set
■ Copy