AppleScript Basics
by Maria Langer

Note: this article is taken from MAC OS X 10.3 PANTHER ED: VISL QUICKSTRT GD, © 2004 Maria Langer Reproduced by permission of Pearson Education, Inc. Publishing as Peachpit Press. ALL RIGHTS RESERVED. To buy this book, visit www.peachpit.com

AppleScript is the scripting language that comes with Mac OS. It enables you to automate tasks and extend the functionality of Mac OS X.

You use AppleScript's Script Editor application to write small programs or scripts that include specially worded statements. AppleScript statements are converted by Mac OS into Apple events--messages that can be understood by the operating system and applications. When you run a script, the script can send instructions to the operating system or applications and receive messages in return.

For example, say that at the end of each working day, you back up the contents of a specific folder to a network disk before you shut down your computer. The folder is large and the network is slow, so you often have to wait ten minutes or more to shut down the computer when the backup is finished. You can write a script that mounts the network drive, backs up the folder, and shuts down your computer automatically. You simply run the script, turn out the lights, and go home. AppleScript does the rest.

In this part of the chapter, I introduce AppleScript's components to give you an idea of how it works and what you can do with it.

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:

  • 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.

Script Editor
Script Editor, which has been completely rewritten for Mac OS X 10.3, 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 can automatically format script statements so they're easy to read.

  • The syntax checker can examine your script statements and identify any syntax errors that would prevent the script from running or compiling.

  • The Open Dictionary command makes it possible to view an application's dictionary of AppleScript commands and classes.

  • The record script feature can record actions as script steps.

  • The Save and Save As commands enable you to save scripts in a variety of formats.


Today's Tip
Recent Tips


Featured Article
More Articles


Search for other computer books at Amazon.com