AppleScript Basics
AppleScript (Figure 19 ) is the scripting language that comes with Mac OS. It enables you to automate tasks and extend the functionality of Mac OS X.
Figure 19. The contents of the AppleScript folder inside the Applications folder.

- You can find a lot more information about AppleScript, including tutorials, sample scripts, and a reference manual, at Apple's AppleScript Web site, www.apple.com/applescript/.
AppleScript Files
There are three main types of AppleScript files (Figure 20 ):
- Scripts (formerly compiled scripts ) are completed scripts that can be launched from an application's script menu or the Script Menu. Double-clicking a compiled script icon launches Script Editor.Applications (or applets ) are full-fledged applications that can be launched by double-clicking their icons.Text files are plain text files containing AppleScript statements. They can be opened with Script Editor or any text editor and can be run from within Script Editor. Double-clicking a script text file icon launches the application in which it was written.
Figure 20. The three basic file formats for an AppleScript: a script (left), an application (middle), and a text file (right). Note the file name extensions for these formats.
[View full size image]

Script Editor
Script Editor is an application you can use to write AppleScript scripts. It has a number of features that make it an extremely useful tool for script writing:
- The Script Editor window (Figure 21 ) can automatically format script statements so they're easy to read.
Figure 21. The Script Editor window with a very simple script. Note how Script Editor formats the script for easy reading.

Figure 22. The Standard Suite of Finder's AppleScript dictionary.
[View full size image]

AppleScript Dictionaries
Scriptable applications include AppleScript dictionaries , which list and provide syntax information for valid AppleScript commands and classes. These dictionaries are a valuable reference for anyone who wants to write scripts.An AppleScript dictionary is organized into suites . Each suite includes a number of related commands and objects . Commands are like verbsthey tell an application to do something. Objects , which include classes and elements , are what a command can be performed on. For example, in TextEdit's Standard Suite, close is a command that can be performed on an object such as window. Properties help distinguish objects; for example, the file type property can help distinguish one file object from another.Figures 22 and 23 show examples of AppleScript Dictionaries for two applications: Finder and TextEdit. If you've worked with previous versions of Script Editor, you may notice that the Dictionary window has been reworked for Mac OS X 10.4 to better organize information. Colored symbols help visually distinguish between suites, commands, classes, elements, and properties. You can click an item in one of the top three columns or a link in the bottom half of the window to instantly display related information in the bottom half of the window.
Figure 23. The Standard Suite of TextEdit's AppleScript dictionary.
[View full size image]

- Although dictionaries are helpful for learning valid AppleScript commands, they are not sufficient for teaching a beginner how to write scripts.
AppleScript Utility
AppleScript Utility, which is new in Mac OS X 10.4, enables you to set various scripting options, such as the default script editing application, and install or remove a Script Menu. When installed, the Script Menu adds a menu full of example scripts to the menu bar. You can modify this menu by removing scripts you don't use or adding your own custom scripts.
- AppleScript Utility replaces Install Script Menu and Remove Script Menu, two utilities that appeared in the Mac OS X 10.3 version of AppleScript.
Folder Actions
Folder Actions is a feature of Mac OS X that works with AppleScript. You create a script that performs a specific task, then attach that script to a folder. When the folder is modified in a predefined wayfor example, when it is opened or a file is added to itthe script activates and performs its task.How can Folder Actions help you? Here's an example. Suppose you're writing a book and every time you finish a chapter, you need to upload a copy of it to an FTP site so your editors can download and review it. You can write a script that uploads any new file added to a folder to the FTP site. Attach that script to a folder and voilà ! Every time you save a copy of a chapter to the folder, it is automatically sent for review.
- To learn more about writing scripts for Folder Actions, visit www.apple.com/applescript/folder_actions/.