Language Guide

CHAPTER 8
Handlers
236 Subroutine Denitions and Calls
SYNTAX
( on | to ) subroutineName ( [ paramVariable [, paramVariable ]...] )
[ global variable [, variable ]...]
[ local variable [, variable ]...]
[ statement ]...
end [ subroutineName ]
where
subroutineName (an identifier) is the name of the subroutine.
paramVariable (an identifier) is a parameter variable for the actual value of the
parameter. You use this identifier to specify the parameter in the body of the
subroutine.
variable is an identifier for either a global or local variable that can be used in
the handler. The scope of a local variable is the handler. You cannot refer to a
local variable outside the handler. The scope of a global variable can extend to
any other part of the script, including other handlers and script objects. For
detailed information about the scope of local and global variables, see “Scope
of Script Variables and Properties,” which begins on page 252.
statement is any AppleScript statement.
The parentheses that enclose the series of positional parameters in the syntax
definition are a required part of the language. They are shown in bold to
distinguish them from parentheses that show grouping but are not part of the
language. The parentheses must be included even if the subroutine definition
doesn’t include any parameters.
For examples of subroutines with positional parameters, see page 238.
Subroutine Call, Positional Parameters 8
A subroutine call for a subroutine with positional parameters lists the
parameters in the same order as they are specified in the subroutine definition.