Language Guide
CHAPTER 8
Handlers
246 Command Handlers for Script Applications
By default, a startup screen appears before the script runs. The user must click
the startup screen’s Run button or press the Return key before the Finder
actually sends the Run command. This allows the user to read the description
of the script before running it. If the Never Show Startup Screen checkbox is
selected in the Script Editor’s Save As dialog box when the script application is
created, the script runs immediately without displaying the startup screen.
You can also send a Run command to a script application from within another
script. For information about how to do this, see “Calling a Script Application”
on page 251.
Open Handlers 8
All applications that are compatible with System 7 can respond to the Open
command, even if they aren’t scriptable. The Finder sends an Open command
to an application whenever the user drags file, folder, or disk icons over the
application’s icon and releases the mouse button. The Open command is sent
even if the application is already running.
Like any other application, a script application receives an Open command
whenever the user drags file, folder, or disk icons over the application’s icon. If
the script in the script application includes an Open handler, the statements
within the handler run when the application receives the Open command. The
Open handler takes a single parameter; when the handler is called, the value of
that parameter is a list of all the items whose icons were dropped on the script
application’s icon. (Each item in the list is an alias; you can convert it to a
pathname by using as string.)
For example, this Open handler makes a list of the pathnames for all items
dropped on the script application’s icon:
on open names
tell application "Scriptable Text Editor"
make new window
repeat with i in names
set iPath to (i as string)
set selection to iPath & return
end repeat
save front window in file "List of Files"
end tell
end open