Name
open handler
Syntax
on open(list_of_aliases) set item1 to the first item of list_of_aliases as string display dialog "Here's the path of the first object you dragged over¬ me: " & item1 end open
Description
An open Apple event is sent to any Mac application when you drag file, folder, or disk icons on to its own icon in the Finder. If an icon is not highlighted when you drag the object over it, then the application or other object associated with that icon is not designed to handle these drag-and-drop events. If you drag files and other icons over an AppleScript applet, the applet receives an open command that triggers any open handlers that are defined in that applet. They look like this:
on open(list_of_aliases)...end open
The open handler has one parameter—a
list type containing alias
objects for all the items that were dragged to the applet. If the
user only drops one item on the applet icon, then the
open subroutine’s parameter
will contain a list with one item in it. You can
code the open handler to take purposeful actions
with files and folders that are dropped on the applet in any way you
see fit. Example 2-1 in Chapter 2
shows a script that displays the file type and creator type of any
valid object that is dropped on the applet.
Tip
If the applet does not have an open handler or has an empty open handler, then the applet does not take any actions when you drop an object on it; it just opens then quits simultaneously.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access