Script Properties
A script property (often just called a property) is a variable defined and initialized at the top level of a script object through a special statement called a property declaration . The syntax is:
propertypropertyName:initialValue
For example:
script s
property x : 5
end scriptThe abbreviation for property is prop.
A property is a variable, so its value can be set and fetched in the normal way. For example:
script s
property x : 10
display dialog x -- 10
set x to 5
display dialog x -- 5
end scriptA property declaration can appear only at the top level of a script object. But the script as a whole is a script object. Therefore a property declaration can appear at the top level of the script, and the script object that owns it is the script as a whole. This is a legal script:
property x : 5 display dialog x
A script property declaration is like set, not like copy. When a script property is initialized to a value where this makes a difference (a list, a record, a date, or a script object) it is set by
reference (see "Set by Reference" in Chapter 7). Here's proof:
property L : {1, 2, 3}
script s
property LL : L
set end of LL to 4
end script
run s
L -- {1, 2, 3, 4}Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access