Creating a Drag-and-Drop Script Application

Although the sample script you created is useful, it would be more useful as an application with an icon on your desktop. Then you could drag files that you wanted to sort into folders and drop them on the application's icon. This would cause the application to run and move the files to their appropriate folders. You wouldn't have to open AppleScript Editor every time you wanted to sort files into folders, and you could sort more than one file at a time. Applications respond to this type of drag-and-drop Apple event, and so can AppleScripts.

You already know that AppleScript can save a script as an application. With a little extra work, you can make an application with drag-and-drop capability, so you can simply drag files to it to choose them.

Retrieving dropped files

Remember that when you drop a set of icons on an application in a Finder window, the Finder sends that application an Open Documents message that includes a list of the files you dropped on the icon. This message is sent to all applications, even to applications that you create yourself with AppleScript.

Figure 14.4

This script uses conditional statements to determine where to put a file.

9781118499894-fg1404.eps

You need to tell your script to intercept that event message and retrieve the list of items that were dropped onto the application icon. Place the following statement at the beginning of ...

Get OS X Mountain Lion Bible 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.