Renaming files
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.

1
For a GUI program, I highly reccomend [R-Name][http://www2.mitsuya.nuem.nagoya-u.ac.jp/~tagaya/mte/archives/my_software/rname/index.html].
No affiliation, just a happy customer of this free utility.----- Or, just use the perl: perl -e 'foreach () { ($a = $) =~ s/([^]+)([^]+).jpg/$2$1.jpg/; rename ($, $a) }'
I'm sure there's a shorter way to do it, but I'm drawing a blank right now.
by bitweever @ 14/07/2005 2:07 am • Permalink •
2
And there was me, hoping for a nice, simple post to read before I truck off on my hols...
{;¬)
by Mr.D. @ 14/07/2005 6:08 am • Permalink •
3
I highly recommend FileWrangler for this stuff. Nice GUI utility. Just gotta bug the developer to add automator support!
http://homepage.mac.com/christopherdrum/blogwavestudio/index.html
by Nik @ 14/07/2005 1:07 pm • Permalink •
4
D'oh! I guess there's my answer. One last time: It should be "foreach (<*.jpg>)"
In case this doesn't work, it's (less than)*.jpg(greater than).
Skilled in Perl, not so much in HTML.
by bitweever @ 14/07/2005 7:07 pm • Permalink •
5
There's supposed to be a (without the spaces) within the () in the foreach (). Not sure if I left that out, or if it was edited out because it looked like a tag...
by bitweever @ 14/07/2005 7:07 pm • Permalink •
6
The Plaid Cow: Looks nice, but I like command-line programmes for this kind of thing, because they are so easy to integrate into other scripts.
bitweever: Neat!
Mr. D.: Sorry about that!
Nik: That looks pretty good too.
by bsag @ 17/07/2005 1:08 pm • Permalink •
Page 1 of 1 pages