Renaming files

· general ·

I tried putting together a little Automator workflow to thumbnail some selected images in iPhoto and rename them. It worked well enough, but the thumbnailing component only allowed a suffix to be added to the file, whereas I wanted a prefix. I was able to work around it with another workflow to get selected files, trim the suffix off, then add it to the beginning of the filename. It worked, but it was hardly elegant.

Then I spotted a nice Perl script mentioned on a MacOSXHints thread about renaming files. Michael Forman's ren-regexp is really useful. Rather than just renaming files you specify, you can give a pattern to match for searching and replacing. So renaming files like DSC01234_thumb.jpg to thumb_DCS01234.jpg can be done in one easy step:

ren-regexp 's/(.*)_thumb.jpg/thumb_$1.jpg/' *

It's really neat and also has a spiffy -t switch, which shows you the result of your command without altering any files; a useful dry run when you are about to rename hundreds of files.

Since Automator workflows can include shell scripts, it becomes very easy to simplify the workflow. I know that there are quite a few such utilities around (both command-line and GUI), but this one just appealed to me. Like all the best *nix commands, it does one thing exceptionally well.