Language Guide
CHAPTER 2
Overview of AppleScript
22 Expressions
You can use operations within AppleScript statements, such as:
tell application "Scriptable Text Editor"
delete word 3 + 4 of document "Test"
end tell
When you run this script, AppleScript evaluates the expression 3 + 4 and
uses the result to determine which word to delete.
Variables 2
When AppleScript encounters a variable in a script, it evaluates the variable by
getting its value. To create a variable, simply assign it a value:
copy "Mitch" to myName
The Copy command takes the data—the string "Mitch"—and puts it in the
variable myName. You can accomplish the same thing with the Set command:
set myName to "Mitch"
Statements that assign values to variables are known as assignment statements.
You can retrieve the value in a variable with a Get command. Run the
following script and then display the result:
set myName to "Mitch"
get myName
You see that the value in myName is the value you stored with the Set command.
You can change the value of a variable by assigning it a new value. A variable
can hold only one value at a time. When you assign a new value to an existing
variable, you lose the old value. For example, the result of the Get command in
the following script is "Pegi".
set myName to "Mitch"
set myName to "Pegi"
get myName