Language Guide

CHAPTER 8
Handlers
Scope of Script Variables and Properties 253
You can declare a property and set its initial value using a statement like this:
property x: 3
The scope of a property declaration can be either a script object or an entire
script. The value set by a property declaration is not reset each time the script
is run; instead, it persists until the script is recompiled.
A global declaration is much the same as a property declaration except that it
doesn’t set an initial value:
global x
The scope of a global variable declaration can be limited to specific handlers or
script objects or can extend throughout an entire script. Like the value of a
property, the value of a global variable is not reset each time a script is run.
However, the value of a global variable must be set by other statements in
the script.
To set the value of any property or variable, use the Set command. (You can
also use the Copy command for this purpose.)
set x to 3
If the variable has not previously been declared, the Set or Copy command
declares it as a local variable. But in some cases it is also necessary to declare
a local variable explicitly.
local x
Like a global declaration, an explicit local declaration doesn’t set an
initial value.
The preceding examples represent the four basic forms for declaring variables
and properties in AppleScript. The sections that follow describe how
AppleScript interprets these four forms of declarations within handlers, within
script objects, and at the top level of a script.