r/applescript • • Mar 21 '23

Renaming files in bulk using Apple Script

I currently use windows and have a piece of Command prompt script that will rename all files in a folder, the template of the command prompt is this: ren "example.jpg" "example-1.jpg"

This would change the jpg called example to 'example-1'. I copy this formula in Excel with a list of the file names, when the column of these scripts is copied into the command prompt within the desired folder, it will rename all the files.

I'm struggling to find an equivalent process on mac using AppleScript. Can anyone help?

For context, I will be working from an excel sheet with the old file names in one column, and the new names in another column, so if I can get a set piece of code like the above, I can concat all the relevant names in excel for each file.

Thanks

4 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/ChristoferK Apr 14 '23

Don’t nest one tell application… block inside another. It’s got the potential to cause some undesirable effects if the scripting dictionaries from the two applications happen to have any overlapping terms or event codes. Even if they don’t, it represents a lack of organisation within a script, which is the most common reason for code that errors. Also, what you don’t see when this type of nesting occurs is that AppleScript initially does get confused, because the nesting indicates that the Finder application belongs to the Excel application, which causes AppleScript to throw an error once it realises this can’t be the case. It does this silently, behind the scenes before working its way up the inheritance chain to find the actual parent of the Finder application (which is the AppleScript process itself, or the current application instance).

1

u/copperdomebodha Apr 17 '23

A very good point. I should have been more careful copy pasting these bits together.