AppleScript in OS X Mountain Lion
AppleScript is one of two technologies offered by OS X Mountain Lion that make it easy to automate repetitive actions on your Mac. AppleScript is “programming for the rest of us.” It can record and play back things that you do (if the application was written to allow the recording — Finder, for example, was), such as opening an application or clicking a button.
You can use it to record a script for tasks that you often perform, and then have your Mac perform those tasks for you later. You can write your own AppleScripts, use those that come with your Mac, or download still others from the web.
Describing AppleScript to a Mac beginner is a bit like three blind men describing an elephant. One man might describe it as the Macintosh’s built-in automation tool. Another might describe it as an interesting but often-overlooked piece of enabling technology.
The third might liken it to a cassette recorder, recording and playing back your actions at the keyboard. A fourth (if there were a fourth in the story) would assure you that it looked like computer code written in a high-level language.
They would all be correct. AppleScript, a built-in Mac automation tool, is a little-known (at least until recently) enabling technology that works like a cassette recorder for programs that support AppleScript recording. And scripts do look like computer programs. (Could that be because they are computer programs? Hmm . . .)
If you’re the kind of person who likes to automate as many things as possible, you might just love AppleScript because it’s a simple programming language you can use to create programs that give instructions to your Mac and the applications running on your Mac.
For example, you can create an AppleScript that launches Mail, checks for new messages, and then quits Mail. The script could even transfer your mail to a folder of your choice. Of course, OS X 10.4 Tiger also introduced Automator, which includes a whole lot of preprogrammed actions that makes a task like the one just described even easier.
AppleScript is a time-and-effort enhancer. If you just spend the time and effort it takes to understand it, using AppleScript can save you oodles of time and effort down the road.
Therein lies the rub. This stuff is far from simple; entire books have been written on the subject. Still, it’s worth finding out about if you’d like to script repetitive actions for future use. To get you started, here are a few quick tips:
You can put frequently used AppleScripts in the Dock or on your Desktop for easy access.
Apple provides a script menu extra that you can install on your menu bar in AppleScript Utility’s Preferences window — along with a number of free scripts to automate common tasks, many of which are in the Example Scripts folder. (An alias to that folder is present in the AppleScript folder.) Furthermore, you can always download additional scripts from Apple.
Many AppleScripts are designed for use in the toolbar of Finder windows, where you can drag and drop items onto them quickly and easily.
Other scripts can enhance your use of iTunes, iPhoto, and iDVD.
AppleScript Editor (in the Utilities folder inside the Applications folder) is the application you use to view and edit AppleScripts. The cool thing is that you can create many AppleScripts without knowing a thing about programming.
Just record a series of actions you want to repeat and use AppleScript Editor to save them as a script. If you save your script as an application (by choosing Format→Application in the Save sheet), you can run that script by just double-clicking its icon.
If the concept of scripting intrigues you, open the Scripts (in the root-level Library) folder. Rummage through this folder to check out the scripts available. When you find a script that looks interesting, double-click it to launch the AppleScript Editor program, where you can examine it more closely.