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

Jun 11, 2015 2:05 PM in response to Tony T1

Hi Tony,


Thank you for your reply and sorry - I did not realize that my post did not reply directly to the post I was referencing.


This should hopefully be a one time operation. We changed our entire inventory over to a new set of part numbers and so I need to rename all my image files for our website. I was using the part of the thread where you set up an Automator Workflow and inserted a shell script I thought I had it working but have since realized I do not. It says workflow complete - but doesn't do anything. No files are altered. I inserted the piece about moving the files to a new folder. Here are two screen shots - one of my csv file and one of my Workflow set up. If you don't mind would you take a look and see if you can determine what I'm doing wrong... I read through the whole thread in case there were edits or modifications so that I would hopefully not be wasting anyone's time but at this point I'm in need of help! Much appreciated. Thanks again!


User uploaded file


In case you can't read it from the image below - this is the shell script used (with your move to new folder mod)


cd "$1"


while read line


do


OldImageName=${line%,*}


NewImageName=${line#*,}


mv "$OldImageName"

"Desktop/NEWFOLDER/$NewImageName"


done <"$2"

User uploaded file

Oct 18, 2015 12:28 PM in response to Tony T1

I really appreciate you putting this script in for Automator because I have the same issue. I think I have copied the form you laid out in my Automator but after I run the program - it apperars to run ok (all green checks) but I can't find the resulting images with their new names. this is what my Automator looks like. -- I have two file folders on my desktop - one named Old Image Names (this contains 10 Jpeg files with their old names) and a second folder named New Image Names ( this contains a single CSV file named statestudentnumberonly with 10 numbers )

Thanks for any help you can offer.


User uploaded file

Nov 2, 2015 4:38 AM in response to Tony T1

Hi Tony!


Sorry to be picking up this issue again, but I've been reading through the whole thread and after a while it's gets messy. I lost track of which step I should follow in order for it to work after trying several steps and changing back and forth of the AppleScript etc.


If it's not too much to ask I would love some further help from scratch.


I've created the .csv file and placed all images in a folder - How and where should I place these files?

And what script am I supposed to write in the last step for the Shell Script? Please write the full code with clear marks where and what I need to change.

As I've been trying several steps mentioned earlier in this thread the closest I've come in order for it to work is that the script runs without errors but nothing happens to the file names...

Note that I have zero experience from using these tools in OS X so please use a language that I can understand 🙂


Thank you very much in advance!


(Sorry about the Swedish language in screenshot!)

User uploaded file

Nov 3, 2015 6:44 AM in response to Mark Jalbert

Mark,


Thanks for your feedback.


I made your requested change and also moved some files according to the script (I did some thinking of my own).

So the script runs without errors now but it doesn't generate the change of the files names... So it runs the script but nothing happens.

Please see attached screenshot.


Thanks in advance for your further assistance!


User uploaded file

Nov 3, 2015 6:56 AM in response to vnylund

vnylund wrote:

I made your requested change and also moved some files according to the script (I did some thinking of my own).

So the script runs without errors now but it doesn't generate the change of the files names...

So it runs the script but nothing happens


The change was for debugging purposes, not to move files.

There should be a file on your Desktop named "debug,txt", please post a few lines from that file.

Nov 3, 2015 7:14 AM in response to vnylund

vnylund wrote:


Tony,


You are referring to my answer to Marks post. Please my answer to your post above.

I made your change in the script but no .txt file was generated on my desktop. So I can't provide you with the data you're asking for, sorry!


ok, first get the script back to where it was.

change:

echo mv "$OldImageName" "$NewImageName" >> $HOME/Desktop/debug.txt

to:

mv "$OldImageName" "$NewImageName"

Now, before the if statement, add:

echo mv "$OldImageName" "$NewImageName" >> $HOME/Desktop/debug.txt

Is there a debug.txt file created on the Desktop now?

Nov 4, 2015 6:28 AM in response to Tony T1

Sorry about my mistake!


Attached is a screenshot of the text in TextEdit and following are lines directly copy pasted:


OldImageName;NewImageName

0256_027.jpg;0256027L.jpg

0283_3KH.jpg;PI02833KHL.jpg

0283_3KH.jpg;PI02833KHM.jpg

0283_3RH.jpg;PI02833RHS.jpg

05DPP036_SM_PD22_n1z1.jpg;Y41R98070.jpg

0705_4RF.jpg;07054RFM.jpg

0705_4RF.jpg;07054RFS.jpg

0705_4RF.jpg;07054RFXL.jpg

0705_4RF.jpg;07054RFXXL.jpg

0711_3RH.JPG;PI07113RHXL.jpg

0877_3YY.jpg;PI08773YYM.jpg

0991706 GEL BLOCK.jpg;EL0991706.jpg

11111029-31._BibTight Elite AmFIB_Blk_2010.jpg;PI11111031021M.jpg

11111029-31._BibTight Elite AmFIB_Blk_2010.jpg;PI11111031021XL.jpg

11111032021.jpg;11111032021L.jpg

11111032021.jpg;11111032021M.jpg

11111033-35._BibTight El. Th.Fleece_Blk_2010.jpg;PI11111035021M.jpg

11111037._Pant Sel. Barrier WXB_Blk_2010.jpg;PI11111037021L.jpg

11111037._Pant Sel. Barrier WXB_Blk_2010.jpg;PI11111037021S.jpg

11111037._Pant Sel. Barrier WXB_Blk_2010.jpg;PI11111037021XL.jpg




User uploaded file

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.