20

Tutorial: Automator Basics

Macapper TutorialIn 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!

11 Comment(s)

Legend: Guest Article Author Contributor
  • 1

    David Mendez said on

    May 28th, 2007 at 11:23 pm

    Very nice tutorial! I have never really gotten into Automator, not sure why exactly, but this is a great walkthrough and certainly makes it more appealing to try out for all sorts of things

     Add karma Subtract karma  +3
  • 2

    Mason said on

    May 29th, 2007 at 12:00 pm

    Does the backup workflow you provided make updated (meaning it only adds modified files after the first backup) backups?

    (subscribed to comments)  Add karma Subtract karma  +1
  • 3

    Uri said on

    May 29th, 2007 at 6:09 pm

    Keep posting more workflows; Automator rocks!!

    (subscribed to comments)  Add karma Subtract karma  +1
  • 4

    Dawud said on

    June 1st, 2007 at 6:02 am

    I’ve found it to be most useful when saved as a Finder plugin. This way I can just right-click on a folder or file, select Automater->BackUp my data is archived. Thanks for the great tutorial.

     Add karma Subtract karma  -2
  • 5

    Michael said on

    June 1st, 2007 at 8:02 am

    Mason:

    No, this action will make a copy of any files you select, even if they have not changed since your last ‘backup’.

    Maybe with Leopard, we can make use of Time Machine as ’subversion for the rest of us’ (and maybe some of the new features in Automator 10.5 will help this process)

     Add karma Subtract karma  -1
  • 6

    Anne said on

    June 1st, 2007 at 9:16 am

    One suggestion I have would be to make the versioned file name in the order:

    XXXX_Backup_YYYY-MM-DDTHHMM

    (this is based on the standard ISO 8601)
    The ‘T’ is based on the standard but it’s not crucial, just make sure you use leading zeros on all numbers and use the 24-hr clock.

    This way, all your like-named files will be chronological when sorted alphabetically
    Filename_backup_2007-06-01T1403
    Filename_backup_2007-06-01T1407
    Other File_backup_2007-05-30T0743
    Other File_backup_2007-05-31T0918

    If you would rather have all files chronological regardless of content, the YYYY-MM-DDTHHMM can go at the start, I use a combination of both systems for different purposes - Date/Time at the start for time specific files (business expense receipts etc.) and Date/Time at the end for content specific files and versioning (this keeps like-named files together)

    This dating system works without the dashes but they make the filenames easier to read (and to make Smart Folders with - Name contains “2007-06″ for a Smart Folder with all June 2007 files)

     Add karma Subtract karma  +3
  • 7

    pinotbob said on

    July 11th, 2007 at 7:11 pm

    I can’t get this to work! “Data Conversion failed” is in the log. Any ideas?

    (subscribed to comments)  Add karma Subtract karma  -2
  • 8

    Jack DeLong said on

    November 25th, 2007 at 9:37 pm

    Thanks for posting this, it was a big help!

     Add karma Subtract karma  -1
  • 9

    Loweded Wookie said on

    November 26th, 2007 at 1:54 am

    I discovered Automator when trying to find a free way to turn iTunes into an alarm clock and from that day on I’ve used it a lot.

    The recording feature in Leopard is cool but not as cool as I would have liked it to be. It’s the equivalent to ScriptIT on Windows but I was hoping more for something like ZenWorks on Novell which is so much better.

    That being said though it means anything can be scripted including closing down applications. The trade off is that it isn’t pretty as it picks up movement so your cursor will go all over the place which looks untidy, but then ScriptIT on Windows is similar.

     Add karma Subtract karma  -1
  • 10

    tl said on

    March 16th, 2008 at 11:58 pm

    How does one set up to trigger a workflow with a keyboard shortcut? thanks. nice tutorial

    (subscribed to comments)  Add karma Subtract karma  +1
  • 11

    Jose Jacob said on

    October 13th, 2008 at 11:32 am

    how do we know that an application supports automator?

    (subscribed to comments)  Add karma Subtract karma  +0
  • 9 Link(s) Referencing this Post

    More at MacApper

    • Discuss 'Tutorial: Automator Basics' in our new Mac Forums

    Post a Comment


    Post your comment below (spam filtered)