Syntax of Defining and Calling a Handler

The parameters, if there are any, follow the name of the handler in both the definition and the call. In the definition, you’re saying how many parameters there are, and supplying the names of the local variables to which they will be assigned; in the call, you’re supplying their values. There are four syntactic cases that must be distinguished, depending on whether the handler has parameters and, if so, how they are specified. (Personally, I think the third and fourth ways to define a handler are silly, and I never use them. But you need to know about them anyway.)

Warning

It is not an error to refer to a handler by its name alone, with no parentheses or parameters. This can be a useful thing to do, if you wish to refer to the handler as a value (see Section 8.6, later in this chapter); but it doesn’t call the handler. If you refer to a handler by its name alone, intending to call it, your script will misbehave in ways that can be difficult to track down.

No Parameters

If a handler has no parameters, the name of the handler in the definition is followed by empty parentheses:

on handlerWithNoParameters(  )
        -- code
end handlerWithNoParameters

The call consists of the name of the handler followed by empty parentheses:

handlerWithNoParameters(  )

Unnamed Parameters

Unnamed parameters are sometimes referred to as positional parameters . This is because the pairing between each parameter value passed and the local variable in the handler that receives ...

Get AppleScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.