mac.column.ted: Quick and Dirty Automator

mac.column.ted: Quick and Dirty Automator

Ted Landau
October 2005

Take a look at any of Apple's promotional material for Tiger (Mac OS X 10.4) and you'll find that a feature that consistently gets a top-billing is Automator. However, I suspect that, if you could check out how many people running Tiger have actually used Automator, you'd get a very low response.

That's too bad. Way too bad. Because Automator is Apple's best ever attempt at a macro-like utility for the masses. With Automator, it is surprisingly easy, and almost fun, to create "quick and dirty" solutions to problems that would otherwise be lengthy and tiresome to complete.

Still, if you remain more than a bit skeptical, I understand your reluctance. I was a skeptic as well. Those of you familiar with the history of Mac OS probably view Automator as a repackaging of AppleScript. You might be tempted to call it "AppleScript for Dummies" if that name did not invoke a book title instead. The trouble with this view is that AppleScript has a tarnished reputation, at least as a mainstream utility. Despite Apple's attempts to promote it over the years as a simple plain-English scripting tool, AppleScript is still pretty technical stuff. If you have no programming skills, and don't care to acquire any, you won't want to bother with AppleScript. Which is pretty much what most Mac users have decided.

But Automator is different. Really. It's not perfect, but for a version 1.0 application, it's pretty darn good. My enthusiasm for it derives from a personal success story. Here's what happened:

While working on the forthcoming edition of my book (Mac OS X Help Line, Tiger Edition, due out in December), I received the following note from my publisher's production staff:

"Because of a really annoying habit that Photoshop has of cutting off names at the first period when doing batch processes, I really encourage everyone NOT to name graphics with multiple periods. I would much prefer that graphics be named something like 'Fig 04-09.tif' than 'Fig. 04.09.tif.' Also, Photoshop prefers 'tif' to 'tiff.'"

Unfortunately, I had already completed almost all the figures for the book by this point ? and they had all been named the "wrong" way. They had two periods and used "tiff" instead of "tif." I didn't know if Photoshop was really as fussy as was being claimed but I had neither the time nor the inclination to find out. "Fix the problem not the blame," as the saying goes, was my attitude. So the question became: Do I tell the production guy that the unpleasant task of renaming all several hundred of my figures falls to him, or do I volunteer to do it myself, or could I find some way to automate the task so neither of us had to do it?

"Hmm...," I mused, "Automate the task...Automator. Was this new software the answer?" My inclination was to give it a try and find out. But even if I could get it to work, I remained concerned about the "hump" dilemma. The dilemma (which crops up when first using any program with a potentially steep learning curve) is that, while it might turn out that using an Automator workflow could accomplish the task in next to no time, doing so first requires that you get over the hump of actually creating the workflow. If it takes three days to create the needed workflow, for example, and especially given that this was likely to be a one-time-only task, it would be quicker to manually rename the files in the Finder instead. So the question now became: Can Automator get over the "hump" sufficiently fast to make it worth using?

[Continued...]

I set about to find out. For the record, at this point, I had never used Automator except to play with it a bit after Tiger first came out. I knew a little about how it worked. But this was my first attempt at using it to accomplish a real-life task.

I launched Automator. I figured that the most likely place to find appropriate Actions for what I needed was in Finder Actions, so I selected Finder from the Library column. I then scanned the list of Actions to see if there was anything appropriate. Bingo! There was an Action called Get Folder Contents. As the figures for each chapter of my book were in a separate folder, this seemed a likely place to start. I double-clicked it to add it as the first step in my workflow.

Next, I wanted to make two separate changes to every file in a folder: (1) Change the first period in each name to a hyphen and (2) change each instance of "tiff" to "tif." This would change, for example, "Fig 1.03.tiff to "Fig 1-03.tif". What I needed was a command to rename files. Sure enough, there was an Action called "Rename Finder Items." I added it to my workflow ? twice (once for each change). When adding each Rename Action, Automator asked me if I also wanted to add an action to create a backup copy of the files to be renamed (presumably as a safeguard against making an irrecoverable error). To keep things simple, I chose "Don't Add." Instead, I made a duplicate of the figure folders myself before running the workflow.

The Rename Action listing includes a pop-up menu from which you can select what type of change you want to make. One item is "Replace text." That sounded like what I wanted, so I selected it for both instances of the Action in my workflow.

Focusing on the first Rename Action, a minor problem was that I did not want to simply say replace "." with "-", because there were two periods in each name and I only wanted to replace the first one. My solution was to enter "Fig 1." in the Find text box and enter "Fig 1-" in the Replace text box. This would change "Fig 1.03.tiff", for example, to "Fig 1-03.tiff". But this created another problem: I didn't want the workflow to be restricted to just Chapter 1. I wanted it to work for all chapters. I discovered the easy solution to this dilemma in the Options section for this Action: enable the checkbox to "Show Action When Run." I wasn't certain this would really do what I wanted, but it seemed like it would.

Setting up the second Rename Finder Items action was much simpler. I just enter "tiff" in the Find text box and "tif" in the Replace text box. Done.

Figure 1. My finished workflow.

Unless I had overlooked something, this appeared to be all I needed to do. Rather than test/debug such a simple workflow from Automator, I decided to directly install it and try it out for real. From the File menu, I selected Save As Plug-in. I chose this, rather than Save or Save As, because (in one of the few things I had previously learned about how Automator worked), this facilitated saving the workflow in the right location and format to be accessible from the Automator item in Finder contextual menus. I named the workflow "Convert Figure Names" and chose "Finder" as the "Plug in for" selection. [Note: This workflow/plug-in gets saved in ~/Library/Workflows/Applications/Finder.]

Figure 2. The "Save as Plug-in..." dialog.

I was now ready to try out my creation. Back in the Finder, I went to the folder for Chapter 1 figures and Control-clicked its icon to get the contextual menu. I scrolled down to the Automator item. From the item's hierarchical menu, I selected the newly added Convert Figure Names workflow. In a few seconds, a dialog appeared that gave me the chance to change "Fig 1." and "Fig 1-" to something else (such as "Fig 2." and "Fig 2-") ? allowing the same workflow to work with multiple chapters, as I had hoped. I clicked to Continue and waited for the workflow to finish. By the way, you can monitor the progress of a workflow in the menubar, where feedback messages should appear; when the workflow is done, a message that says "Workflow completed" appears.

Finally, the moment of truth. With the workflow done with its run, I opened up the Chapter 1 folder to see the result: every file had been renamed exactly as wanted! Success. I then proceeded to do the same thing for all the remaining chapter folders. Success again. While I did not time myself with a stopwatch, I estimate the entire task, from creating the workflow to running it for all chapters, took well under 30 minutes. In any case, it was much less hassle than changing the name of each file "by hand."

The biggest drawback of Automator (especially as compared to third-party programs such as QuicKeys) is that you cannot create new actions with nearly the ease of creating a workflow from existing actions. This means that if Automator does not include an action you want, you are out of luck ? unless you have the programming skills needed to create new actions. This, of course, defeats the whole point of Automator as a "no-brainer" program.

But there are many tasks that Automator can do with the actions it already has. And more will be added, both by Apple and third-parties, in the months ahead. So the next time you find yourself facing a boring repetitive task, before digging in and doing it the hard way, give Automator a chance. It worked for me. It may work for you too.

This is the latest in a series of monthly mac.column.ted articles by Ted Landau. To see a list of previous columns, click here. To send comments regarding this column directly to Ted, click here.

Resources
  • More from Mac Musings
  •  

    Join the discussion

    Conversation powered by Livefyre

    Don't Miss
    Hot Products
    Trending on CNET

    HOT ON CNET

    Up for a challenge?

    Put yourself to the real tech test by building your own virtual-reality headset with a few household items.