Creating a More Complex Script

You now know how to use AppleScript Editor to create a simple AppleScript script. This type of script, however, has limited value. A simple script that doesn't take advantage of the full AppleScript language is not very intelligent.

More frequently, you'll use AppleScript to create more complex scripts. This section explains how to create a full-blown script quickly and use the resulting custom utility to augment an application's capabilities.

Making a Finder utility

Your OS X disk is full of special folders, but when someone sends you a file, it's up to you to figure out where the file belongs. For example, you have to sort TIFF and JPEG files into your Pictures folder, QuickTime files into your Movies folder, and MP3 files into your Music folder. You also have to classify and put away fonts, sounds, and so on. The Finder doesn't help you sort out any of this.

You can, however, write a simple script that recognizes certain types of files and uses the Finder to move files to the folders where you want the files to go. The destination folders can be any folders that you have permission to change. These include all the folders in your home folder. If you log in as a user with administrator privileges, the destination folders also can include folders in the main Library folder.

Beginning the script

To begin writing a new script in AppleScript Editor, choose File⇒New or press +N, and then type the following statement in the script editing area of the ...

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.