Take Control of Customizing Tiger: Automator
Editor’s Note: The following article is an excerpt from Take Control of Customizing Tiger, a $5 electronic book available for download from TidBits Electronic Publishing. In a May 2005 excerpt from the book, Matt Neuburg looked at Spotlight —this article focuses on Automator.
The ultimate purpose of a computer is automation. Even when you’re doing something as simple as editing text in a word processor, you’re automating actions that would be terribly tedious if you had to perform them yourself, one at a time. (If you don’t believe me, trade your computer in for a typewriter. Slam the carriage return at the end of every line; remember to add extra space before every paragraph; get all the spelling right; make a mistake and retype the whole page—no thanks!)
Nevertheless, your computer doesn’t know in advance everything you will want to do, and there are times when you probably find yourself performing the same actions over and over again. Or perhaps there are things you don’t do, because, although you know how you could do them, the prospect would be too tedious and time-consuming. This is a bad state of affairs. It means that the roles have been reversed: you, the human being, are being automated, instead of the computer.
Since the dawn of computer time, the traditional way to solve this problem has been to write a new computer program that performs the repetitious or tedious actions. But writing a brand new program shouldn’t be necessary when applications you already have on your computer can perform the desired individual steps. The problem is to get those applications to perform those steps themselves, rather than your having to do it one step at a time. This is why Apple created AppleScript, which lets you assemble a sequence of actions that your existing applications can perform, and then set that sequence going whenever you like.
However, AppleScript is a programming language, and many users have an aversion to programming languages. So Apple introduced, in Tiger, a new automation technique—an application called Automator, which lets you, the user, assemble a series of steps (called actions ) into a single sequence (called a workflow ) without doing any programming at all. A workflow can be saved as a document, so once you’ve created a workflow, you can open it again later and perform the same sequence of steps, in a single move.
Tiger comes with a number of Automator actions; these actions are stored in /System/Library/Automator. You may also expect that many third-party actions will be written as Tiger matures; as you acquire such actions, you’ll store them in /Library/Automator or in your own user ~/Library/Automator.
It is also possible for a third-party application to be written in such a way as to include its own actions; in a case like that, its actions will be available in Automator, but you won’t see them as individual files. For example, when you update to the latest version of BBEdit, about 20 new actions for manipulating text will magically appear in Automator.
Extra for experts
An application that responds to AppleScript (that is, a scriptable application) is a good candidate to be the target of an Automator action, and behind the scenes, the heart of an Automator action that targets a scriptable application typically is an AppleScript script. So, when you construct a workflow in Automator, you may well be stringing together a series of AppleScript scripts—except that you don’t need to know AppleScript; the scripts are already written, and you never see them.
Make an Automator workflow
Using the actions included with Tiger, you can start stringing actions together to form workflows right now, in ways that will allow you to do things you may previously have thought impossible. Automator workflows may well become an important part of your customization of Tiger.
To illustrate the process of making an Automator workflow, let’s pose ourselves a task, for purpose of illustration. Our example will be extremely simple. I’m not trying to teach you all about Automator; I just want to show it to you so that you’ll understand the basics and won’t be afraid to experiment on your own.
Often, I’ve seen people say this on an Internet newsgroup: “I have a folder full of files, and I want to list the names of those files in a word processor. How do I do it?” Now, you can solve this problem in a number of ways. You can use Terminal—but many people don’t like Terminal, or are afraid of Unix commands. You can use Bare Bones Software’s freeware TextWrangler —but perhaps you don’t realize that. Anyhow, the real question is: How can you solve this problem for yourself?
This is the sort of situation where you ought to turn to Automator and see if the applications and actions on your computer can help you perform the desired task. Let’s do it!
Step 1: Start up Automator. (It’s in the Applications folder.) A new workflow document opens.
Let’s look at what we’re seeing. On the left are listed all the Automator actions (the Action column). The list can be filtered in two ways: you can select one or more applications in the Applications list (in the Library column), to show only the actions that apply to them, and you can type in the Search field at the top of the window. On the right is a big blank area where you’ll drag each action you want to use, arranging them to form a top-to-bottom sequence.
Step 2: Think about the problem. How does it start? “I have a folder…” So your sequence’s first step is to specify the folder. Click Applications in the Library column (because we want to search all actions), and type
folderinto the Search field, to help you find actions having to do with folders.
Step 3: The first found action is Get Selected Finder Items. Click it to read more about it in the pane at the bottom of the left side. The description says: “This action gets the selected items and passes them to the following action.”
Step 4: This sounds promising, but it would be more convenient not to have to start by selecting the desired folder; it would be better if a dialog would appear, asking what folder we want to use. Wait—the third action in the list is Ask for Finder Items. Click it and read its description: “This action lets the user choose Finder items in a dialog when the workflow is run.” Perfect! Drag Ask for Finder Items into the main area on the right (as shown in the screenshot above).
Step 5: As with many actions, this one has certain modifiable characteristics. (The action can be displayed by name only or with all its characteristics showing; to toggle between those modes of display, click the triangle at the left of the action’s title.) It turns out that Ask for Finder Items has a Type pop-up menu: we can limit the types of items to files, folders, or both. Excellent! We know we want to choose a folder to operate on, so change the Type pop-up menu to Folders. Also, we get to determine the prompt text that will show in the Open dialog; instead of “Choose a Finder Item:”, enter
Pick a folder to list:.