Apple Script to rename images using CSV file

Hello, I have build a website using a Woocommerce for Wordpress. The site is going to have over 1200 images and they need to be renamed appropriately for each product. I've never used Apple Script before but after hours and hours of searching I have noticed people with similar issues have managed to solve the problem using AppleScript.


I have attached a screenshot of the CSV file first 20 files - also the images are all saved in a folder with the names _DSC7916 copy 2.jpg etc etc.


Hopefully my issue makes sense,


User uploaded file

MacBook Pro with Retina display, iOS 7.0.4

Posted on Jan 30, 2014 5:16 PM

Question marked as Top-ranking reply

Posted on Jun 13, 2015 6:33 AM

I just noticed that the OldImageName files in the csv file snapshot you posted has no extensions, is that correct?

(If the actual file has extensions, that's the problem)


For example, if your listing the file in the cvs as 56958 but the file is actually 56958.jpg or 56958.gif, then the script (or the cvs file) needs to be adjusted.

165 replies

Nov 4, 2015 3:22 PM in response to vnylund

I Had the same problem where the script would run without error but with no changes to my image names - due to my immediate need I ended up going to out source website (upwork) and hired a guy to write the script exactly as I needed and then email it to me. I have run it 6 times renaming 500 images each time - without error. I would love to learn to write the script but this time I took the easier way - although more expensive - cost me $60US but in this case well worth it. Good luck

Nov 9, 2015 6:13 AM in response to Tony T1

Hi Tony!


Sorry for the lack of response here but I've been away for a few days.


I tried the script and this time it actually felt like something happened since it took a few seconds for the script to run. And the .tmp file showed on the desktop for a little while as well before it disappeared.


What's the next step? 🙂


Edit: I realized that I didn't place any images on the desktop so I did it again and it worked 😀!!!!!! One image didn't get renamed though but I'll check if there's something wrong in the .csv file. But as for now I hope it will work.


Edit#2: The script didn't process the last line in the .csv file so I just added a "dummy line" at the bottom and it renamed the last image as well.


Thank you very much Tony!!!





User uploaded file

Feb 8, 2016 1:59 PM in response to Tony T1

Here are the sample csv lines:

OldImageName,NewImageName

Student1.pdf,Aizenberg_Samuel_0028

Student2.pdf,Alexander_Pierce_0024



Here are the results of the debug.txt file


cp OldImageName /Users/orrj/Documents/NewImageName

mv OldImageName NewImageName

cp Student1.pdf /Users/orrj/Documents/Aizenberg_Samuel_0028

mv Student1.pdf Aizenberg_Samuel_0028

Feb 8, 2016 2:55 PM in response to jorrflv

jorrflv wrote:


I am trying to follow the bash script, but I can see right now that there will be an issue because the folders are on my desktop not in my documents folder... that would make a difference yes?


Should not make a difference.

The first action selects the Folder that has the files.

Now that I think about it, there is no need to debug the cd.


Run the Workflow Again (with no echo commands), then when it completes, click the [Results] box and you'll see the directory that the workflow is changing to:

In this example, I selected the Untitled Folder on my Desktop:


User uploaded file


When you click [Results] you should see the folder with the files

Feb 8, 2016 4:27 PM in response to Tony T1

added the line no go... here are the results of terminal command


OldImageName,NewImageName^MStudent1.pdf,Aizenberg_Samuel_0028^MStudent2.pdf,Alex ander_Pierce_0024^MStudent3.pdf,Anderson_Eric_8583^MStudent4.pdf,Apalategui_Aime e_7987^MStudent5.pdf,Attanasio_Nia_7722^MStudent6.pdf,Ayoub-Butcher_Angelina_009 9^MStudent7.pdf,Badger_Gage_7751^M

Dec 2, 2016 1:51 PM in response to Tony T1

Hi Tony, sorry to bug on this old thread, but like the previous poster said you seem to be very helpful on this thread. I've used the script you created and it works perfect. My question can this script be modified for it to look under multiple folders? All the image files are within their own folder and was wondering if the script would be able to just find all the files in the different directories and rename the files according to the CSV file. As an ideal i'm attaching the screenshot of my CSV file, if that helps. if you notice that all the files start with a different number so each number corresponds to the file folder. Example of folder structure attached aswell. Any help would be greatly appreciated it! So far this script you created only works for files in one folder right? Thank you so much!User uploaded fileUser uploaded file

Dec 4, 2016 9:25 PM in response to Tony T1

Thank you so much for you reply! Yes your understanding to what I'm trying to accomplish is correct. I tried running the script but the files I tested on, didn't rename. Can this script be used with the same set up you had for in automator or do I have to run it separately? Sorry, I'm a noob when it comes to scripting and still learning and trying to understand a lot.

Another question if i had all the folders in another folder on my desktop (ex. /Desktop/Color_Rename/14901) would i have to put the path in as follows cd ~/Desktop/Color_Rename/


Also by reading past posts do we still need to add the string if we're using a CSV file created on a Mac Excel?


Thank you again for helping me!

Dec 5, 2016 3:03 PM in response to Tony T1

Hi Tony,


I noticed that you were using tr to change the carriage return to a newline. If you are attempting to change \r\n line-ending, then this usage of tr will result in \n\n. If that is not your planning, then this article shows how to use Perl and its '\R' meta-character to produce a solitary newline ending. The '\R' usage is basically, “I don't care what the line ending is, just make it the replacement value.”

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Apple Script to rename images using CSV file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.