Language Guide

CHAPTER 6
Expressions
Script Properties 157
Defining Script Properties 6
The syntax for defining a script property is
( prop | property ) propertyLabel : initialValue
where
propertyLabel is an identifier. The rules for specifying identifiers are listed in
“Identifiers” on page 27.
initialValue is the value that is assigned to the property when you first run the
script that contains the property or when you save it or check its syntax.
After you define a script property, you change its value the same way you
change variable values: with the Set or Copy command. You can get a script
property value using the Get command or by using it in an expression.
Using Script Properties 6
To see how script properties work, try running the following script, which
contains a script property called theCount.
property theCount : 0
set theCount to theCount+1
display dialog "The value of theCount is: " & theCount
as string
The first time you run the script, the value of theCount is set to 0. The Set
command adds one to theCount, and the Display Dialog command displays
the value of theCount, which is 1.
Now run the script again. The Set command adds 1 to the value of theCount
(which is still one because it has not been reset), and the Display Dialog
command reports a value of 2. If you run the script a third time, the value of
theCount is 3, and so on.
Now save the script as a compiled script. Close the script, and then open and
run it without making any changes. The value of theCount is one more than it
was before you closed the script.