An Automator backup workflow tutorial

For today’s tip, I’m going to show you how to use Automator to write a very simple backup utility—you’ll be able to compress and copy a given folder with a single mouse click. While not an ideal backup solution, it’s a great way to make sure your most important folders can be easily backed up. The general idea of the hint isn’t necessarily the specifics of this backup script, but rather to show how simple and yet powerful Automator workflows can be.

To implement this hint, you’ll need OS X 10.4, of course, as Automator didn’t exist prior to that. You’ll also need a FireWire drive, iPod in disk mode, or other such device where you can store your backup. (You could, of course, store it on the same drive as the original files, but that’s not really a backup—if the main drive fails, you’ll still lose everything.)

Creating the workflow

Launch Automator, which you’ll find in /Applications, and then click on the Finder entry in the Library column. In the Action column, drag Get Selected Finder Items to the blank work area on the right. This action will look at whatever you have selected in the Finder and pass it on to the next step of the workflow. Leave Finder select in the Library column, and drag Create Archive into the work area, below the Get Selected Finder Items entry. As you might have guessed, this will create an archive of the chosen Finder items in the previous step. In the Save As box in the Create Archive workflow, give your archive a name such as Folder backup or whatever.

The filename issue is the only real glitch with this simple solution: Automator in 10.4 can’t pass the name of the Finder items to use as the name in the Create Archive step, so you’re left with a generic name. I’m hoping Leopard’s Automator fixes this oversight.

Now drag the Rename Finder Items from the Library area to the workflow, below the two existing steps. You’ll see a warning dialog, asking if you’d like to add a Copy Finder items action. You can click Don’t Add, as we’re only going to be renaming the archive we just created. In the Rename Finder Items workflow entry, leave the first pop-up set to Add Date or Time, and then set the remaining menus to format the date as you like. For instance, I set the date separator to a dash, and the separator between the filename and the date to an underscore, and formatted the date to be added with leading zeros.

If you plan on making more than one backup a day, drag the Rename Finder Items action into the work area again, right below the one you just created. (You’ll see the same warning dialog; choose Don’t Add, as you did before.) Again leave the pop-up set to Add Date or Time, but set the Format pop-up to ‘Seconds from 12 M.’ Change the separator for the filename if you wish (again, I used an underscore). By adding the number of seconds since 12 midnight to the filename, you’ll be insured of having a unique name for each and every archive.

For the last step in your simple backup workflow, drag the Finder’s Move Finder Items action to the bottom of the work area. Click the To pop-up in the workflow, then click Other at the bottom of the list. Navigate to your external hard drive, iPod in disk mode, or other backup media (which must be mounted in the Finder for this workflow to work), and pick a destination for the folder—you might want to create a new folder ( Desktop Mac Backups or whatever) to hold your backed-up files.

At this point, use File -> Save to save your work, and name the workflow whatever you like ( Backup workflow ) and save it somewhere in your user’s folder.

Test the workflow

That’s it; your simple backup script is now done. I created this screenshot of a completed workflow, so you can see what it looks like. To test your workflow, switch to the Finder and select a small folder—use something that’s got a handful of files in it, not every document you’ve created in the last 10 years. With that folder selected, switch back to Automator and click the Run button. You should see a small green check mark next to each step of your workflow as the workflow is processed, and hear a tone when the workflow completes. If you see a red “X” next to any step, you’ll have to figure out why it didn’t work—compare your workflow to my image and see if you can spot anything that doesn’t look similar. Don’t proceed to the next step until your workflow is working when you run it directly in Automator.

Make it one-click simple

Since having to launch Automator every time you wanted to back up a folder would be a real pain, we’re going to convert the workflow into a contextual menu entry in the Finder. Select File -> Save As and name your new plug-in—use a name that will make sense when you see it in a list of entries, maybe something along the lines of Back up this folder . Leave the Plug-in For pop-up set to Finder and click OK.

Just that easily, you’ve created a new entry in the Finder’s contextual menu. Switch to the Finder, highlight your small test folder again, and control-click on it. When the pop-up menu appears, scroll down to Automator and pick ‘Back up this folder’ from the sub-menu that appears. In the menu bar, you’ll see your workflow’s progress, and then hear the successful ‘workflow complete’ noise. From now on, you can backup any folder you like via this contextual menu item—just make sure your backup media device is mounted before you try to use the workflow.

Just the beginning

Hopefully this hint gives you some idea of just how easy it is to work with Automator, and some idea of the things you might be able to do with it. Even if you’re not a programmer, it’s a powerful tool that can help make certain repetitive tasks much simpler.

Subscribe to the Best of Macworld Newsletter

Comments