run handler
Whether you like it or not, most of your scripts contain a
run handler implicitly or invisibly. What Apple
Computer calls an “implicit run
handler” involves all the statements in a script
except for property definitions, subroutine definitions, and any
script objects (see Chapter 9). This means that
all of these statements are enclosed in an invisible on run...end run
subroutine block. This implicit
run handler is called each time:
The applet icon is double-clicked.
The user chooses the applet from the Apple menu.
The user chooses the applet from the Apple Menu Items folder.
The applet is placed in startup disk:System Folder:Startup Items and the computer is restarted.
You can explicitly code the run handler to
clarify to readers of your code exactly what happens when the applet
receives a run command, as in the next example.
If this script did not include the on run...end run
statements, then its implicit run
handler would still encompass the statements:
add( )
and:
display dialog "I received a run command " & howmany & " times"
The applet property howmany
increments by 1 each
time this applet receives a run command:
property howmany : 0 on run add( ) display dialog "I received a run command " & howmany & " times" end run on add( ) set howmany to howmany + 1 end add
Sending a run
command to an application, as in tell app
"Photoshop 5.5" to run
, loads the
application if it is not already running. Use activate
to gain the focus of the application (i.e., highlight the
program on the desktop) when it is already running. Sending a
run command to an AppleScript causes its
implicit or explicit run handler to execute.