Digital Media Mac Blogs > Mac

Everyday Automation - Renaming Files


If you repeat a computing task more than three times, consider automating it! "Everyday Automation" will provide the occasional idea on how to delegate repeating tasks to AppleScript and Automator. And in case you don't find the presented scripts and workflows to be useful as they are, they might at least inspire you to create your own.

Renaming multiple files at once in the Mac's Finder can be a pain, unless you use a renaming utility. While there is a wide range of such utilities available as third-party offerings, Mac OS X has a flexible renaming tool built right in.

One of the many actions that ship with OS X's drag-n-drop scripting tool, Automator, is the powerful "Rename Finder Items," which lets you add a date/time stamp or arbitrary text to a file or folder name; change the name's case; add a sequential number; or replace existing text in the name. And each of these functions comes with plenty of options on how and where to (re)place what.

All it takes to utilize this Automator action as a self-contained renaming tool, is embed it in its own short-and-simple workflow. Here's how.

Creating the "Rename Files…" workflow

EA_Rename_AutomatorNewWorkflow.jpg

Open the Automator application. When launched, Automator will present a dialog box from which you can choose a "starting point" for a new workflow. Select "Files & Folders," leave the Get content from: menu set to "my Mac," and choose "Use files & folders selected in the Finder when workflow runs" from the lower pop-up menu. Click "Choose" to dismiss the dialog.

Automator creates a new workflow and adds the "Get Selected Finder Items" action to that workflow. To complete the workflow, you need to add just one action: "Rename Files" from the "Files & Folders" category. Typing "rename" into the search field above the list of actions should be the most effective way to find that action in the library.

Drag the action into the workflow below the "Get Selected Finder Items" action. Automator will now ask whether you would like to add a "Copy Finder Items" action. Unless you prefer to keep copies of files you rename (not all that likely, I would assume), click "Don't Add."

EA_Rename_AutomatorFinishedWorkflow.jpg

Next, select the file name operation you will likely use most often, from the menu in the upper left. I opted for "Replace Text". Finally, click the Options button and check the "Show this action when workflow runs" option so that Automator will display this action in a dialog box whenever it's run.

Save the workflow via Save As Plug-In from the File menu, naming it "Rename Files…" and ensuring that "Finder" is selected in the Plug-In For: menu.

Launching the workflow with on-board tools

To run an Automator workflow on a Finder selection, right-click (or Command-click) on that selection, and, in the contextual menu, select the desired workflow from the More > Automator sub-menu. Note the notification in the menu bar: it shows the progress for the currently running workflow, and it also lets you stop the workflow by clicking on the Stop sign icon.

Launching the workflow more efficiently

Launching the workflow with a universally accessible keystroke is more efficient than the menu method, but requires additional software. As an example, here's how to assign a keyboard shortcut to the Rename Files… workflow with the help of Quicksilver.

EA_Rename_QSTrigger.jpg

In Quicksilver's Triggers > Custom Triggers preferences pane, click on the plus sign at the bottom of the window, and select Hot Key. In the dialog sheet that opens, search for "rename files" in the top-most field. Once you've selected the workflow, the default action will change to "Execute Workflow". Click Save.

Ensure the newly created Trigger is selected in the list and click the "i" icon to open its Info panel. Assign the keystroke you would like to use for this workflow -- I use Ctrl-R -- in the "Settings" pane. Also, you may want to limit this Trigger's scope to avoid conflicts with other application's short-cuts by choosing "Enabled in selected applications" on the "Scope" pane and typing "Finder" into the text field.

(For a much deeper discussion on how to assign keyboard short-cuts to AppleScripts and Automator workflows, see Hit-and-Run: Launching AppleScripts with Keyboard Shortcuts.)

Now, instead of tediously renaming files one by one, you can delegate all the grunt work to Automator after summoning the "Rename Files…" workflow with just a single keystroke.

Categories





AddThis Social Bookmark Button
Comments (12)
Read More Entries by Jochen Wolters.

12 Comments

Chris Goblin said:

Automater is a good solution.
But there are some other third-party tools (like ABFR, Renamer4Mac or Renamerox) which are not free but they have much more features than automater.

You can not find features like presets, undo or roman numerals in automater.

I use Renamerox and I'm very happy with it.

If you want to try it, here is the link:
http://www.renamerox.branox.com

Ted

If you mainly use this technique to rename pictures, have a closer look at iPhoto or Aperture (or similar programs by other software companies) to manage your photos.

Not only do they offer tagging and other features to more comfortably organize your photos; both also offer batch renaming, including adding a running index to the renamed photos.

Ted Mackel said:

As a Realtor, I take tons of pictures and my move to Mac had me frustrated in renaming graphic files with sequential designation. Nifty little tool and absolutely no need to go third party.

dadecoders said:

If you take a little time and go through your My Pictures folder and apply this technique(i.e rename all files at a time to all your photos, the next time you try to find a specific photo you'll be glad that you did. And if you get into the practice of applying this technique right after you download your images to your computer, your digital photos will be well-organized and up-to-date as you accumulate digital memorie

open folder which contain images or any other files.select images(files) which you want to rename sequentially.
now whatever files you are selected are appear in blue coloured selected files.
just right click on the first image(file) and select renamehere type "marriage"then press enterNow you can see that all the files are name as
marriage
marriage (1)
marriage (2)....
,

Chris:

Of course, third-party utilities like Renamer4Mac (which, according to its website, is not free, by the way) are a reasonable alternative, but the point I am trying to make with this blog post is that Mac-users should launch Automator on their machines at least once to see what kind of functions that utility has to offer. The Rename Finder Items action is just one example, but it is one whose usefulness literally every user will be able to value.

Chris Hong said:

Why not use Renamer4Mac? The user interface is intuitive, it works, and it's free!

Glad you like this blog post, xmanoel.

Beyond the renaming action, there is so much more interesting stuff in Automator, that I cannot understand why Apple is so mum about this technology.

xmanoel said:

Nice somebody has bring the nice Automator task to the spotlight.

I have been using it myself for few months back. And I am quite happy about it.

PD/
The sh script could be way better using bash or zsh parameter expansion ;-)

bob said:

Reinvent the wheel? I think the script trumps the pretty on that front. Oh, and for flexibility and efficiency. You've got me on the user friendliness though.

bob said:

Reinvent the wheel? I think the script trumps the pretty on that front. Oh, and for flexibility and efficiency. You've got me on the user friendliness though.

Bob:

Somehow, I knew that I had to expect this kind of comment. ;)

And yet, I wonder what the benefit of such a script would be over the Automator solution: flexibility, efficiency, user-friendliness? Why re-invent the wheel if a feature-rich Rename Finder Items action is already available?

bob said:

for i in $(ls); do
new=20081014$i
mv $i $new
done

Leave a comment


Recommended for You

Topics of Interest

Archives


 
 


Or, visit our complete archive.