Language Guide
CHAPTER 8
Handlers
252 Scope of Script Variables and Properties
Similarly, to launch a non-stay-open application and run its Open Handler, use
a Launch command followed by an Open command, like this:
tell application "NonStayOpen"
launch
open {alias "HardDisk:MyFile", ¬
alias "HardDisk:MyOtherFile"}
end tell
For example, if the Open handler on page 246 were saved as a script application
called “NonStayOpen,” the script in the preceding example would cause the
handler to create a list of the two specified pathnames.
Scope of Script Variables and Properties 8
The declaration of a variable or property identifier is the first valid occurrence
of the identifier in a script. The form and location of the declaration determine
how AppleScript treats the identifier in that script.
The scope of a variable or property declaration is the extent to which
AppleScript recognizes the declared identifier within a script. It is often
convenient to limit the scope of a particular identifier to a single handler—
that is, to treat the identifier as a local variable. After a local variable has
served its purpose, its identifier no longer has any value associated with
it and can be used again for other purposes elsewhere in the script.
If you want the value of a script to persist after a script is run, or if you wish
to use the same identifier in several different places in a script, you can declare
it as either a script property or a global variable. AppleScript keeps track of
properties and global variables across multiple handlers and script objects
within a single script.
This section describes how AppleScript interprets various forms of declarations
within handlers, within script objects, and at the top level of a script. You
should be familiar with the section “Run Handlers,” which begins on page 243,
before you read this section.