Basics of Automatic Automation in OS X Mavericks
OS X Mavericks offers a pair of technologies — AppleScript and Automator — 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, 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 others from the web.
Automator is programming without writing code. With Automator, you string together prefabricated activities (known as actions) to automate repetitive or scheduled tasks. How cool is that?
Basics of AppleScript in OS X Mavericks
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.
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. 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:
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 here.
AppleScript Editor (in the Utilities folder inside the Applications folder) is the application you use to view and edit AppleScriptsJust record a series of actions you want to repeat and use AppleScript Editor to save what you recorded 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 double-clicking its icon.
If the concept of scripting intrigues you, open the Scripts (in the root-level Library) folder. Rummage through this folder and when you find a script that looks interesting, double-click it to launch the AppleScript Editor program, where you can examine it more closely.
Basics of Automator in OS X Mavericks
Automator does just what you’d expect: It enables you to automate many common tasks on your Mac. If it sounds a little like AppleScript to you, you’re not mistaken; the two have a common goal. But this tool (introduced in OS X Tiger) is a lot simpler to use, albeit somewhat less flexible, than AppleScript.
For example, in AppleScript, you can have conditionals (if this is true, do that; otherwise do something else), but Automator is purely sequential (take this, do that, then do the next thing, and then . . .).
The big difference is that conditionals allow AppleScripts to take actions involving decision-making and iteration (while this is true, do these things); Automator workflows can’t make decisions or iterate.
The upsides to Automator are that you don’t have to know anything about programming and you don’t have to type any archaic code. Instead, if you understand the process you want to automate, you can just drag and drop Automator’s prefab Actions into place and build a workflow (Automator’s name for a series of Actions).
Computers do only what you tell them to do, although they can do it faster and more precisely than you can. But all computers run on the GIGO principle — garbage in/garbage out — so if your instructions are flawed, you’re almost certain to get flawed results.
When you launch the Automator application, you see the window and sheet. Choose one of the starting points if you want Automator to assist you in constructing a new workflow, or choose Workflow to start building a workflow from scratch.
Let’s use Service for the sake of this demonstration.
The Library window on the left contains all the applications Automator knows about that have Actions defined for them. Select an application in the top part of the Library window, and its related actions appear below it.
When you select an action, the pane at the bottom of the Library window explains what that Action does, what input it expects, and what result it produces. Just drag Actions from the Action list into the window on the right to build your workflow.
Automator is a very useful addition to OS X; it’s deep, powerful, and expandable, yet relatively easy to use and master. Do yourself a favor, and spend some time experimenting with ways Automator can save you time and keystrokes. You won’t regret it.
For additional information about AppleScript, Automator, Services, and much more, click here.