Language Guide
CHAPTER 9
Script Objects
Initializing Script Objects 269
handler and property definitions, and does not include any additional top-level
statements, the definition may include an explicit Run handler that begins with
on run. If a script object definition includes neither an implicit Run handler
(in the form of top-level statements) nor an explicit Run handler, the Run
command doesn’t do anything. (For more information about Run handlers, see
“Command Handlers for Script Applications,” which begins on page 243.)
For example, the Display Dialog command in the following script object
definition is executed only if you send a Run command to script object John.
script John
property HowManyTimes : 0
to sayHello to someone
set HowManyTimes to HowManyTimes + 1
return "Hello " & someone
end sayHello
display dialog "John received the Run command"
end script
Initializing Script Objects 9
When you define a script object, you define a collection of handlers and
properties. When you run a script containing a script object definition,
AppleScript creates a script object with the properties and handlers listed
in the definition. This is called initializing a script object. A script object
must be initialized before it can respond to commands.
If you include a script object definition at the top level of a script—that is, as
part of the script’s Run handler—AppleScript initializes the script object each
time the script’s Run handler is executed. (For more information about Run
handlers, see page 243.)
Similarly, if you include a script definition in another handler within a script,
AppleScript initializes a script object each time the handler is called. The
parameter variables in the handler definition become local variables of the