renaming finder items II

renaming finder items introduced a couple of ways to batch-rename files in the finder using either automator or applescript, depending on the complexity of the job. those examples involved altering the existing filename by replacing characters or removing parts of the name. here’s another renaming workflow that was developed when one set of filenames needed to be mapped to a completely different set — hundreds of barcodes named by ISBN needed to be renamed by product code.

Applescript Icon applescript is fantastic for this kind of work because renaming hundreds of files by hand is just about as tedious as it gets. as with most scripting tasks, there are myriad ways this problem could be tackled — here’s just one :

screen grab showing filenames in excel

this solution starts with two lists — original filenames and new filenames — in a single excel worksheet. for this version of the app to work correctly, the worksheet needs to be saved in the same folder as the files to be changed and the worksheet needs to be open in excel.

the app looks through the top level of the folder for files and folders matching the names in column A and changes the filenames to the corresponding ones in column B — simple. files that don’t match a name in the list are skipped. all original file extensions are maintained. files in subfolders remain untouched. here’s a before and after shot of test files :

screen grab showing files before and after name changes

RenameByList is a zipped folder containing the app and a sample excel file. to use it — update the excel spreadsheet to your requirements, put all your files in the same folder and double-click the app :

you can get a copy of RenameByList here

screen grab showing compiled script in script editor

for those interested in this sort of thing…
excel can be a bit of a pain to script. for example, this is the command to extract the entries in column A :
set mgANames to formula of range mgARange

instead of giving us a list of names :

{"9781234567890", "9781234567891", "9781234567892" ...

this command gives us a list of lists :

{{"9781234567890"}, {"9781234567891"}, {"9781234567892"} ...

that’s why we need to loop through the original list (mgANames) with this command — to convert the list of lists into a straight list :
set end of mgOriginalNames to item 1 of item x of mgANames

the other way would be to just loop through the cells in excel to make the list in one pass like this :

tell used range to set mgRowCount to count rows
repeat with x from 2 to mgRowCount
  set end of mgOriginalNames to formula of cell ("A" & x)
  set end of mgNewNames to formula of cell ("B" & x)
end repeat

but this script was developed and tested through script editor before being saved out as an app. and this second method is MUCH slower through script editor (although not much different when run as an app). try it yourself.

• related post : renaming finder items : renaming using automator or applescript.
• related post : renaming finder items III : renaming by creation date.

macgrunt icon


7 thoughts on “renaming finder items II

  1. Hi

    I am not very experienced in this subject. I’m currently involved in a project for online sales and rental of percussion instruments for orchestras. We have about 250 pictures of instruments, all named in Dutch. I need to create an English, French and German picture folder… and translate every picturename accordingly. This has been done in a spreadsheet and a .CVS file. I would like to rename every picture in Finder in bulk, and this is (so far) the only solution I have found. So I would really use the app! Thanks in advance for your help.

    Kind regards


    Johan De Croppe – Ghent / Belgium

  2. Hello,
    when I start the App, it show the messagewindow, but I´m not able to neither Start nor Exit – it hangsup. When I try to start from the applescript-Editor I get the Errormessage:

    „«class 1756»“ versteht die Nachricht „count“ nicht.

    I put all files to rename and the excelfile where I stored your files. The workbook is opened in excel

    I´m using OS X 10.6.8 and Excel Mac2012

    • Hi Peter

      So, you are able to open it in Script Editor but get the error message when you try to run it — is that correct?
      If this is the case, you should be able to see which line causes the error.
      Could you please tell me that line — hopefully we can find the problem that way.


  3. Hi macgrunt – I’m working with a large dataset of multiple Excel workbooks/files. I need to batch rename all of these. When I run your script/app, it seems to work up to retrieving the files’ extension (.xsl), but then it quits… trying to figure out what goes wrong. I’m working from Snow Leopard (10.6.8). Any help would be much appreciated!

    • G’day
      A good way to troubleshoot is to open the app in Script Editor (applications > applescript) and run it from there (green ‘run’ button) with the Event Log History window open.
      You get to see what the app is doing and where it hangs up.
      If you like, you can send the resulting transcript to and I’ll see if I can work out what is going on.

  4. Pingback: Renaming Finder Items [Link] « Macdrifter

Leave a Reply to Johan De Croppe Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s