sometimes you need to rename a whole bunch of files. sometimes you find you’re doing the same kind of renaming time and time again. sometimes this gets exceedingly tedious. automator and applescript are perfect for this kind of monkey-work.
in automator, investigate the various options in the rename finder items action. you can add dates and times, renumber files sequentially, change case, all sorts of stuff. the action window also shows you an example of what the final filename will look like — this is a big help when looking at all the different date/time options.
the example below shows how to replace all spaces and hyphens in filenames with underscores (click to enlarge the screen grab). the first ‘find’ field has a space typed in it. after you set it up, save the workflow as an application and drag it onto your sidebar for easy access.
unlike the mounting servers example, this workflow doesn’t need a get specified finder items action — because it works as a droplet instead, which means you just drag-and-drop files onto the app and they’ll be renamed in less time than it takes to say “wow, that’s fast!”. The screen grabs below show filenames before and after conversion (click to enlarge).
but some renaming tasks are too complex for automator and that’s when you need applescript. for example, this script truncates filenames by stripping out everything after and including the first space, hyphen or underscore. perfect for renaming product images for a webshop (and a million other household purposes). download and drag it to your sidebar — it works as a droplet. The screen grabs below show filenames before and after conversion (click to enlarge).
caution: this script works exactly as described, but make sure you’re happy with how the script renames your files before running it on a big batch — you can’t ‘undo’ file renaming in the finder (unless you have a time machine).
you can get a copy of the TruncateFilenames app here
for those interested in this sort of thing…
when an applescript is saved as a droplet, its icon includes a downwards pointing arrow. the on open mgItems line at the start of this script is what allows the saved application to run as a droplet. without that on open command you’d need to find some other way to reference the files to be changed.
you could select all the files first then click the app in the sidebar. if that’s the way you’d like it to work … open TruncateFilenames in your script editor, delete the ‘end open’ line and replace ‘on open mgItems’ with this :
set mgItems to selection of application "Finder"
or, you could click the app in the sidebar first, which would then prompt you to choose the files. if that’s the way you’d like it to work … open TruncateFilenames in your script editor, delete the ‘end open’ line and replace ‘on open mgItems’ with this :
set mgItems to choose file with multiple selections allowed
but surely you’d have to agree that saving it as a droplet is probably the best solution in this case (?).
• related post : renaming finder items II : renaming by list.
• related post : renaming finder items III : renaming by creation date.