Batch rename files using Apple Automator

Automator is a piece of software included with Mac OS X that, as the name implies, is used to automate repetitive computing tasks. It allows users to build a workflow by chaining together a series of predefined actions. When a workflow is run, its actions are initiated in sequence, automating a series of steps the user would normally have to take manually.

Automator can be used with many different types of tasks, but this tutorial describes how to use Automator to batch rename a group of files. This is particularly useful when working with digital images, which tend to come out of the camera with names like “IMG_0032.JPG” or something similar. Using Automator, we can create a simple workflow that will rename those image files in a more helpful way.

Building the Automator task

Find Automator in your Mac’s Applications folder and fire it up. When Automator opens, it will prompt you to “Choose a type for your document.” For our Batch Rename task, we will use the Service type. As the help text reads:

“Services are contextual workflows available throughout Mac OS X. They accept text or files from the current application or the Finder. Services appear in the Services menu.”

Manipulate the menus near the top of the right panel to select the values shown in the screenshot below. (Service receives selected files or folders in Finder).

The panels on the left side of the Automator window contain all available actions, which you can drag into the space in the right panel to create a sequential workflow. In the list under Library at the far left, click Files & Folders to filter the list of actions to include only those relevant to working with — that’s right — files and folders.

Time to add the first action to our workflow: Select Sort Finder Items from the list of actions in the middle panel, and drag it into the area in the right panel labeled “Drag actions or files here to build your workflow.”

The default values (name and ascending) shown in the screenshot can be left as-is. This will ensure the image files are sorted properly before they are renamed.

Next, add the Rename Finder Items action to the workflow. Automator may display a warning asking if you wish to add a Copy Finder Items action, to prevent overwriting the original files. But in this case, we want to change the files, not duplicate them. So click “Don’t Add” to leave out the copy action.

There are several possible behaviors for the Rename Finder Items action, and the default is “Add Date or Time” — which adds a formatted date or time representation to the beginning or end of the existing filename. That’s great, but the default settings for how that date should be formatted are not ideal, so change them to the values indicated in this screenshot:

Adding the date to the beginning of the filename and formatting it as YYYY-MM-DD will ensure that the renamed files are displayed in proper chronological order when sorted by filename, and keeping special characters like slashes and spaces out of filenames is just a good idea.

However, you might not want to use the exact same format every time you run this Batch Rename task. At the bottom of the action box, click “options” and check the box labeled “Show this action when the workflow runs.” Then, whenever the workflow is run, you will have the ability to customize that action’s settings.

If we were to run this action on our original “IMG_0032.JPG” file now, it would be renamed to something like “2012-03-07-IMG_0032.JPG,” which is better, but still not perfect. It would be nice to replace the “IMG_” part of the filename with a short bit of descriptive text to help identify the image.

Add another Rename Finder Items action to the workflow. This time, change the default “Add Date or Time” option to “Replace Text.” Since the text you want to replace will vary depending on the original filenames, you want to be prompted for what to find and what to replace it with each time you run the action. So as before, click “options” and select “Show this action when the workflow runs.”

Just for good measure, let’s add one final Rename Finder Items action. Change the “Add Date or Time” option to “Change Case,” then change the parameters displayed to “Full name” and “lowercase,” as shown below:

Choose File —> Save to save your new service, and give it logical name like “Batch Rename Files.” The completed workflow should look like this:

Using the Batch Rename service

To use the newly-created service, open a Finder window and select the files you wish to rename. Then choose Finder —> Services —> Batch Rename Files (or whatever name you gave your service) from the menubar at the top of the screen.

Or, you can select the image files, right-click, and choose your service from the contextual menu.

Any actions that had the option to “Show this action when the workflow runs” selected will be displayed, allowing you to customize their settings.