I’m fairly new to Automator, in that I’ve used it only once before. What I’m trying to do is clean up a bunch of Android app assets, which are named like so:
01_something
1_something_else
002_something_too
What I want to do is remove the leading digits + underscore, i.e. any leading non alphabetical characters. I imagine this can be done either by having a script that’s smart enough remove them, perhaps by some manner of regex, or by having a prompt that asks me how many characters I want to remove, if Automator even supports that.
Secondly, I’d like to add a prefix to the files, like tile_
or ab_
. Again, if I could select some files in Finder, and choose ‘Add Prefix’ or something, and enter some text into a prompt, that’d be optimal.
Best Answer
There is no need for dedicated file renaming software to do such relatively simple batch renaming operations – Automator will allow you to create services that do what you want.
Your first task (removing a numerical prefix followed by an underscore form file names) can be solved like this:
Add a “Run Shell Script” action and make sure it runs
/bin/bash
and takes its input “as arguments”. Insert the following code:– see the Bash Reference Manual’s chapter on Pattern Matching for an explanation of how this works (recommended reading for this kind of operation anyway :)).
save to the default location as “Remove Prefix”.
– you will now have a “Remove Prefix” in the Service menu of Finder (and the context menu of files and folders) which will rename files so a numerical prefix followed by an underscore is stripped from the file name.
The second task (prefixing the files with a selectable string) is even easier to achieve, using a Standard Automator action:
– when you run the service on one or more files, you will see the following dialog:
(or rather, its equivalent in your system language), where you can edit the prefix you want to use before applying it.
Happy renaming with OS X’ on-board abilities :).