Tutorial: Automator Basics

In case you haven’t heard, Automator rules. Automator is the often under-appreciated and underestimated automation tool, provided by Apple in Mac OS X 10.4 Tiger, to bring the power of automation to users with no need for programming. In this simple tutorial I’ll show you the basics of Automator and walk you through a simple Backup application example. This should give you the solid foundation to start making useful actions for yourself.

The Basics of Automator

Automator LogoFirst, load the Automator editor application located in the Applications folder. On the upper-left hand side of the Automator window you will notice the Library pane which lists the applications on your system that are supported by Automator. If you don’t see your favorite App in this window write the author of the software, only they can add Automator support. Just to the left of the library pane is the Actions pane which lists the available actions for a selected application. These two windows act as your toolbox while making an Automator action. Naturally there is also a search field to quickly find an action without needing to select a specific target application. Below these two panes is the Action Description pane. Here you can find important information about different actions like what sort of “Input” it expects, what “Result” it returns and any other requirements.

This concept may be familiar if you have any experience with the programming concept of “protocol”, if you you are unfamiliar don’t fret! It’s not that hard, I promise. Every Automator action expects a certain “type” of input. For example the iTunes action “Add Songs to Playlist” expects “Songs” as the input, naturally if you sent this action a text file, an email address and a sandwich it would be unable to add them to a playlist. In return for you giving an action what it expects it “promises” to consistently return a certain type of response or “Result”. These Results can often be passed into other actions making a sequence of events that does something useful for you.

To the right side of the Automator window is the Workflow pane. Here you place Actions which will occur one by one from top to bottom. Actions can be placed into the Workflow by either dragging an action to the Workflow pane or by double-clicking on an action.

The toolbar also contains two buttons you’ll be using a lot, the Run (Command R) and Stop (Command .).

Instant Backup Automator Action

This is a handy little Automator action I use all the time on projects or assignments where I’m experimenting with a file (usually code) enough that “Undo” won’t suffice and setting up a version control system feels over-kill. This action when placed in the dock will make a copy of whatever file or folder you have selected in the Finder and conveniently append a date-stamp onto the name of the copy. Please keep in mind that the following example is definitely not the only way and likely not the best way of backing up your files, so while you’re working through the tutorial think of how you would do it better and go ahead and give it a try.

The first step of this workflow involves letting Automator know which file(s) you wish to deal with. For this example we’ll simply tell Automator to make a back up of the file (or folder) that is currently selected in the Finder. To do this you will want to find the “Get Selected Finder Items” action by selecting Finder in the library pane and dragging “Get Selected Finder Items” to the work flow window.

Automator Image 1

Next we will want to copy the file to your backup destination. I’ve created a “Backup” folder in my home directory (the directory named with your user name) in which to place the backed up files. The Action that will do this for us is called “Copy Finder Items”, lets try using the search to find it this time. Drag the action to the workflow pane and take a look at the action “bubble” you’ve created. You will notice that unlike the “Get Selected Items” action this one contains some further controls. In the “To:” drop-down menu I will select my Backup folder. If you choose to place your files elsewhere please change the “To:” destination directory accordingly. There is another option here to replace existing files in the destination directory if they have the same name. I would not recommend you check this box, it will erase similarly named files without asking. If you leave the replace check box unchecked when there is another file sharing the same name the Finder will rename the new file to prevent a collision.

Automator Image 2

Rename your Backup

Although this action is pretty good already, when I’m making many revisions and changes to a file I like to keep track in the file name that it is a backup and the time and date the backup was created. We can do this very simply with Automator.

Automator Backup Image

First I’d like to append onto the file name the suffix “_Backup” to remind me I’m looking at a backed up file. The action we will use to add this suffix, date and time is the “Rename Finder Items” action. As we will use this same action three times in a row go ahead and add three of them to the work flow.

To append the text suffix focus on the first of the three “Rename Finder Items” actions. From the action’s drop-down menu select “Add Text”. In the “Add:” text field type “_Backup”. I preceded the word “Backup” with an underscore, “_”, so the title is easier to read. Set the next drop-down menu to “after name”, this will make the text act as a suffix to the prior name rather than a prefix. Mac OS X recognizes when there is a file extension visible at the end of the file name (.mov, .pdf, etc.) and will append your text between the file name and the file extension.

Automator Image 3

To add the time of day you created the backup you will edit the second “Rename Finder Items” action that you added. This time you will set the first drop-down menu to “Add Date or Time”. Because I want to see when I made this backup rather than when it was last modified I select “Current” from the “Date/Time:” drop down menu. The “Format:” drop-down menu will be the only difference between adding the time and the date, here we will choose “Hour Minute”. Again the we will want to add the text after the name by selecting “After name”. You can choose whichever “Separator:” drop-down selections you find easiest to read for the next two options, I’ve chosen “Dash” and “Underscore”. You can also enable the use of leading zeroes with the final check box. For example, with leading zeros, eight o’clock and one minute in the morning will read 08-01 rather than 8-1, it’s a matter of personal preference.

Automator Image 4

Finally to add the date to the third “Rename Finder Items” action, do the same as you did for time in the second “Rename Finder Items” action but select the “Format:” drop-down menu option “Day Month Year” instead of “Hour Minute”.

Automator Image 5

Finishing Up

Now would be a great time to save your work, this can be done by pressing Command-S or by selecting Save from the File Menu. In the save window you will notice a “File Format:” drop-down, this gives you the choice of saving as a Workflow or an Application. For our example we’ll choose to save an Application. As an Application your Automator action can be double clicked in the Finder and be activated. I would recommend you save your new Automator action “application” to your Applications folder for easy access. A cool little feature of these Automator action applications is that unlike a complied Application built in Xcode you can just drop your creation or one you downloaded that you want to learn from onto Automator to examine and edit its workflow.

Automator Save Box

We’re on the home stretch now, you’ve got a working Automator action but… what to do with it? If you double click on it now you will likely just end up with a backup of your Automator action application in your backup destination (remember it’s setup to backup Finder’s current selection). I think an excellent solution would be to drag your Automator Application to the dock so you can access it anytime from the Finder. Now select the file you wish to backup, click on the your application in the dock and like magic you’ve got a dated backup!

The Future of Automator

Rest assured, your new little robot friend, Automator, will not be disappearing with the release of Mac OS X 10.5 Leopard. In fact Apple is adding many very helpful enhancements to Automator in Leopard that will make the automation process even easier. According to the public WWDC course page, actions will no longer be just scriptable but also recordable in Leopard, that’s really exciting. I can assure you there are other neat things in the works and can’t wait until we can all get our hands on the Leopard version of Automator. Until then, happy Automating!