Language Guide
CHAPTER 6
Expressions
152 Variables
The results of the two types of assignment statements are the same in all
cases except when the value being assigned is a list, record, or script object.
The Copy command makes a new copy of the list, record, or script object,
and the Set command creates a variable that shares data with the original list,
record, or script object. For more information, refer to “Data Sharing” on
page 154.
Using Variables 6
To use the value of a variable in a script, include the variable in a command or
expression. For example, the first statement in the following example creates a
variable, called myName, whose value is the string "Mitch". The second
statement uses the variable myName in place of a string as the default
answer parameter of the Display Dialog command.
set myName to "Mitch"
display dialog "What is your name?" default answer myName
If you assign a new value to a variable, it replaces the old value. The following
script shows what happens when you assign a new value. It uses the Display
Dialog command to display the values. Try running this script:
set myName to "Mitch"
display dialog ("The value of myName is now " & myName) ¬
buttons "Sure Is" default button 1
set myName to "Warren"
display dialog ("The value of myName is now " & myName) ¬
buttons "You Betcha" default button 1
The first Display Dialog command displays the value stored by the first
assignment statement (the string "Mitch"). The next Display Dialog
command displays the value after the second assignment statement (the
string "Warren").