How to batch-rename files using Automator in OS X

Renaming files in OS X is as easy as selecting them and pressing Return; however, if you regularly rename many files then you might benefit from setting up a rename workflow in Automator.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
3 min read

Often when managing collections of files in the OS X Finder, you may find that giving the files unique or patterned names may help in your organization. For instance, if you have a set of image files it may help to quickly append a date or sequential number to the file name; to do so manually might take a while.

At other times, you might wish to quickly append a time stamp or other similar attribute to a file name without having to manually edit the name. As an example of this, if you use the OS X compress feature (available when right-clicking a selection of files) to create a ZIP archive, the compressed file will simply be called "archive.zip," and be easy to confuse with other archives you might be managing; however, you can overcome this by being able to quickly change the archive name to "Archive-DATE.zip."

In OS X you can set up a routine to batch-rename files using Apple's Automator program, where you can make a service plug-in that will offer you options to change names to collecitons of files.

Automator file renaming workflow
With the new service created, set it to act on files and folders in the Finder (1), and then add file renaming actions (2), followed by adjusting those actions' properties and previewing them in the Example area (3). (click for larger view) Screenshot by Topher Kessler/CNET
  1. Create a new Service workflow
    Open Automator and create a new workflow file (press Command-N or choose New from the File menu). Then choose Service from the window of available workflow types (this option will look like a gear).

  2. Adjust Service inputs
    Services act on items you pass to the workflow, which can be images, sound files, or even selected text. In this instances we want to be able to modify all files and folders, so be sure to choose "files or folders" from the first drop-down menu at the top of the workflow, and then choose Finder from the second menu. This second option will ensure the workflow only acts on files and folders from the Finder, and not be available in other applications. If needed you can set the workflow to only act on PDFs or other document types, depending on your needs.

  3. Add a file rename action
    The next step is to add an action that will rename any files passed to the workflow, so drag the Rename Finder Items option from the action library (to the left of the window, under the Files & Folders category) to the workflow window. When you do this, Automator will issue a warning that this action will alter existing files, and provide you with an option to add an action to first copy the files instead of altering them. At this point click Don't Add, and you will see the rename action be available in the workflow with a number of options.

  4. Services menu showing new renaming service
    The newly saved renaming service can be accessed from the OS X contextual menu when you have files selected in the Finder. (click for larger view) Screenshot by Topher Kessler/CNET
  5. Adjust the naming scheme
    Now you can adjust the new action according to your preferences. Using the menu at the top-left of the action, you can choose to add a date or time to the name (the default action), or append text, change the case of the name, add sequential numbering, replace text, or simply rename a single item. At the bottom of the workflow you will see an example of the name that your settings will produce.

  6. Add more file renaming actions
    A single instance of a file-naming action will only change one aspect of the file name, so you can make multiple modifications by adding more renaming actions sequentially. For instance, if you would like to append both the date and time to a file name, you will need two renaming actions. The first will append the date, and the second one will append the time.

  7. Save the workflow
    When your workflow is complete, saving it will automatically place it in the /username/Library/Services/ folder, which will make it available via the OS X contextual menu. Now when you go to the Finder, you can select a group of files or folders, and then right-click them and select your workflow from the Services submenu of the contextual menu.

Using Automator in this way you can create one or several renaming services for your files, but you can also use one of several renaming tools that are available for OS X:

Questions? Comments? Have a fix? Post them below or email us!
Be sure to check us out on Twitter and the CNET Mac forums.