A guide to using OS X’s Automator to create your own software

Whether you prefer OS X or Windows, you've probably heard and likely believe that OS X is a "closed" system that won't let you customise the way you can customise Windows, and that real power-users therefore prefer Windows.

This is a myth.

Unless you're a skilled programmer, the only changes that you can make in Windows, using Windows' built-in tools, are changes that affect the way it looks, not what it does. In contrast, OS X's Automator feature makes it easy for anyone to create miniature applications and utilities that make OS X perform complex tasks with one or two mouse clicks. You can use Automator to automate almost any task that you perform repeatedly in OS X — and you don't need to learn a scripting or programming language to do it. There's nothing like it in any other operating system.

This is the second in a series of articles about advanced features in OS X that almost anyone can use, but which don't get in the way of beginners who don't need them. The first instalment of the series was OS X Mountain Lion: Hidden mysteries of the Option key. This article is for OS X users who want to learn automation techniques but aren't ready to learn a scripting or programming language. The third article in the series will be an introduction to OS X's built-in scripting language, AppleScript.

Automator is so flexible that it's impossible to produce a complete summary of how it works, but here are some of the basics. You use Automator to create an app that performs exactly the series of steps that you want it to perform. Each step gets performed by a kind of building block called an Action; the full sequence of steps is called a Workflow. You can save a Workflow as a standalone application that runs when you double click it, or you can save it as any of various other kinds of OS X utilities, including Calendar Alarms and Services — a Service being Apple's name for a utility program that runs only from menus and pop-up menus in other OS X applications, not as a separate app that you run by double clicking it in the Finder.

How to automate iTunes

I'll describe one extremely simple Workflow, then another one that you can create in two varieties, one simple, one more complex.

Right, for the very simple Workflow — and I'm offering this only as an example to show how Automator works — we're going to look at an app that sets the volume in iTunes, switches on an iTunes equaliser setting, and then plays one or more songs or playlists. More complicated examples can perform a whole symphony of actions that include mailing and archiving files, converting image files to other formats, adding watermarks to Microsoft Word documents, creating user accounts, finding contacts whose birthday occurs in the next week and sending them emails, or any combination of these and dozens of other actions.

Advanced users can create their own customised building blocks by adding the provided Run AppleScript or Run Shell Script actions to their workflows. These special Automator actions let you insert code snippets written in a variety of programming languages, such as Perl, Python, Ruby, any of the standard UNIX shells, and – easiest of all – OS X's native scripting language, AppleScript.

To build the iTunes playlist playing app that I just described, start by launching Automator and choosing Application from the gallery of document types. In Automator's two-pane window, you'll see lists of Actions and Variables on the left and an empty pane on the right. From the Actions library on the left, select the Music category, then from the list of music-related Actions, drag "Set iTunes Volume" to the right-hand pane. A building block named "Set iTunes Volume" will appear, and you can drag a slider to set the volume level you want. Next, from the Actions library, drag the "Set iTunes Equaliser" item to the right-hand pane. In the resulting building block, check the box that turns on the equaliser, and select an equaliser profile, for example "Treble Booster" or "Spoken Word."

Now that we've set up iTunes the way we want it, drag the "Get Specified iTunes Items" Action from the library on the left to the empty pane on the right. You'll see a building block named "Get Specified iTunes Items," with an "Add…" button at the bottom. Click that button, and select one or more of your existing playlists — or you can add one or more songs from any playlist, or alternatively you can add a mix of playlists and individual songs.

Now go back to the Actions list on the left, and drag "Start iTunes Playing" into the right-hand pane, below the "Get Specified iTunes Items" block that you added in the previous step.

You're now ready to test your app. Click on the Run button at the top of the Automator window — ignore the warning message about running your workflow in Automator itself — and listen to your selected songs playing through your speakers. Click on File/Save… and save your app to your desktop or anywhere else, with any name you choose.

Serve yourself with an Automator Service

Automator can create many other kinds of utilities that aren't standalone applications but plug-ins and add-ons for the Finder and other apps. The one I use most is the option to create a "Service" — a utility that you typically run from the Ctrl-click menu of a file selected in the Finder, or from the Services menu of any application, or from the menu that appears when you Ctrl-click a block of text you've selected in an application. To create a Service, start up Automator (or use File/New if it's already open) and select Service from the menu.

By default, your new Service does something with selected text in any application, but you can change this so that your service works with (for example) phone numbers, dates, or email addresses. You can select from these and more in the "Service receives selected" drop-down menu at the top of the right-hand pane in which you edit your Automator script.

One easy Automator service is one that automatically emails any block of text that you've selected in Safari to yourself. Create a new service, as described above. At the top of the right-hand pane, select Text from the first drop-down ("Service receives selected"), and Safari from the second drop-down ("in"). Then simply drag just three Actions into the right-hand pane: from the Utilities category, choose "Copy to Clipboard"; from the Mail category choose "New Mail Message" and specify the recipient (yourself) and a subject heading; and again from the Mail category, choose "Send Outgoing Messages." Save the service under any name you choose, and start using it.

Make it more powerful with variables

You can make this service more useful through an advanced and powerful Automator feature called "Automator Variables." In this example, we'll use an Automator Variable to insert the page URL from Safari (the URL of the page where you selected the text) into the subject header of the message that the service emails to yourself. Let's start again from the beginning. Create a new service. As in the previous example, set it to receive selected text from Safari. Now, perform the following steps:

1. From the list of Utilities actions, drag Set Value of Variable into the right-hand pane. In the "Variable:" field, select New Variable… and enter the name ClippingText. This step saves the selected text from Safari into a variable that our Automator service will use in a later step.

2. From the list of Internet actions, drag Get Current Webpage from Safari into the right-hand pane.

3. From the Utilities list, again drag Set Value of Variable into the right-hand pane, and in the "Variable:" field, select New Variable…, and name it PageAddress. These two steps place the URL from your Safari page in a variable that the service will use later.

4. From the Utilities list, drag Get Value of Variable into the right-hand pane, and make sure that the "Variable:" field says ClippingText, not PageAddress.

5. From the Mail list, drag New Mail Message into the right-hand pane. Enter your email address in the "To:" field. In the "Subject:" field, type "Clipping from," then a space.

6. At the foot of the right-hand pane you will see a list of your variables: PageAddress and ClippingText. Drag PageAddress into the Subject: field, after the text that you typed in the preceding step. This will put the URL of the Safari page into the Subject line of your message to yourself. The content of the message will be the ClippingText variable that you retrieved in step 4.

7. Again from the Mail list, drag Send Outgoing Messages into the right-hand pane.

Now save your service, and use it to send clippings from Safari to yourself.

You can do even more with this Workflow. For example, if you want to add a Cancel/OK dialog box to this Workflow, open it in Automator (it will be on the File/Open Recent list), and, from the Utilities list, drag Ask for Confirmation to the very top of the right-hand pane. In the top blank fields, enter something like "Send clipping to yourself?" and leave the second field empty or add some explanatory text. Save the service, and it will now prompt you before sending an email.

Also, you can add the current date and time to the Subject field of your email message to yourself. In the left-hand pane of the Automator window, click Variables instead of Actions; in the Library, choose Date & Time, then drag Today's Date into the Subject field in the New Mail Message action block in the right-hand pane. Put a space between the new variable and whatever you've already entered in that field. Then, if you like, add a space, and drag the Current Time variable into the Subject field. Now, the subject line will show the original page URL and the date and time you clipped the text in the message.

Folder Actions

For decades, the Mac has included a "Folder Action" feature that automatically performed one or more actions on any file dropped into a specified folder. It still amazes me that Windows doesn't have this feature built-in. Until Automator arrived, you needed to understand AppleScript to create your own Folder Actions, but Automator lets you build Folder Actions as easily as you build any other Automator Workflow. Just create a Workflow with the Actions that you want to apply to any file that you drop into a specified folder, and tell Automator which folder you want to attach the Workflow to. For example, you could create a Folder Action that automatically creates a PDF from every image file that you drop into the folder.

For further information on Automator, visit www.macosxautomation.com, and if you need friendly, expert help when creating your Workflows, visit the Automator forum at www.macscripter.net.

If you're a Windows fanatic, please don't waste bandwidth by posting comments saying that most of what I've described here can be done in Windows using VBS (Visual Basic Script) or the Windows PowerShell. I know that already, and I've been using VBS and PowerShell under Windows for years and years, so you don't need to tell me about them. The point of this article is that under OS X, you don't need to climb the steep learning curve of VBS or PowerShell and you don't even need to write a script. Automator gives anyone who uses OS X the same power that only high-tech experts have under Windows. It's one of the reasons I use Windows when I need to, but I use OS X because I want to.