userremoved

Q: 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,

 

Old-Image-New-Image.jpg

MacBook Pro with Retina display, iOS 7.0.4

Posted on Dec 27, 2015 4:28 PM

Close

Q: Apple Script to rename images using CSV file

  • All replies
  • Helpful answers

Previous Page 2 of 11 last Next
  • by userremoved,

    userremoved userremoved Dec 27, 2015 4:28 PM in response to Tony T1
    Level 1 (0 points)
    Dec 27, 2015 4:28 PM in response to Tony T1

    Hello again,

     

    Sorry for keep having to get in touch, I've been spending hours on this, sometimes it works and other times I get errors. I run into errors everytime I switch files. I've got to resave all the images again because I forgot to add the .jpg suffix and they won't upload into Wordpress (stressful for a friday)

     

    I've attached a picture, I can only select 'Storage' in Variable, if i click the dropdown and click New Variable it just makes a 'Storage 2'. Maybe it's not even that which is the issue.

     

    I hand typed 'Choose CSVFile' in the Ask for Finder Items.

     

    Thanks for you help

     

    Automator-Error-again---Variable.jpg

  • by Tony T1,

    Tony T1 Tony T1 Jan 31, 2014 5:51 PM in response to userremoved
    Level 6 (9,249 points)
    Mac OS X
    Jan 31, 2014 5:51 PM in response to userremoved

    The variable name (Storage) is not the issue.  Name does not matter, as we're not referencing it by name (we're using $1 and $2).

    The problem appears to be that the line read is a file that does not exist (or an typo in the csv file).

     

    Just need to add a line to test if the file exists.

    So try with this:

     

    cd "$1"

    while read line        

    do        

         OldImageName=${line%,*}

         NewImageName=${line#*,}

         if [ -e $OldImageName ] ; then

              mv "$OldImageName" "$NewImageName"

         else

              echo "$OldImageName" >> ~/Desktop/Errors.txt

         fi

    done <"$2"

     

    If there is an error, it will be listed in the file Errors.txt on the Desktop

  • by Tony T1,

    Tony T1 Tony T1 Jan 31, 2014 6:26 PM in response to Tony T1
    Level 6 (9,249 points)
    Mac OS X
    Jan 31, 2014 6:26 PM in response to Tony T1

    Opps!, forgot to quote if [ -e "$OldImageName" ]

     

    Use:

     

    cd "$1"

    while read line       

    do       

         OldImageName=${line%,*}

         NewImageName=${line#*,}

         if [ -e "$OldImageName" ] ; then

              mv "$OldImageName" "$NewImageName"

         else

              echo "$OldImageName" >> ~/Desktop/Errors.txt

         fi

    done <"$2"

     

    If there is an error, it will be listed in the file Errors.txt on the Desktop


  • by userremoved,

    userremoved userremoved Dec 27, 2015 4:28 PM in response to Tony T1
    Level 1 (0 points)
    Dec 27, 2015 4:28 PM in response to Tony T1

    Hey Tony,

     

    Using the latest Script I got...

     

    Error.txt

     

    Old Image Name

  • by userremoved,

    userremoved userremoved Dec 27, 2015 4:28 PM in response to userremoved
    Level 1 (0 points)
    Dec 27, 2015 4:28 PM in response to userremoved

    I saved out the CSV file again and readded the photos into the folder, a test of 5 images worked. I'll do all 1000+ tomorrow and see how it goes

  • by userremoved,

    userremoved userremoved Dec 27, 2015 4:28 PM in response to userremoved
    Level 1 (0 points)
    Dec 27, 2015 4:28 PM in response to userremoved

    There is something that happens during the Automator that changes the .jpg file. They cannot be loaded into Wordpress I get an error message saying:

     

    “Ditch_Witch_SK_300.jpg%0D” has failed to upload due to an error

    Sorry, this file type is not permitted for security reasons.

  • by Tony T1,

    Tony T1 Tony T1 Feb 1, 2014 8:32 AM in response to userremoved
    Level 6 (9,249 points)
    Mac OS X
    Feb 1, 2014 8:32 AM in response to userremoved

    kittersa wrote:

     

    Hey Tony,

    Using the latest Script I got...

    Error.txt

    Old Image Name

     

    Good!  That's the Header in your CSV FIle, so all other lines should have processed without error.

    If you don't want the Error.txt file produced, just comment out the 2 lines with a # like so:

     

    cd "$1"

    while read line      

    do      

         OldImageName=${line%,*}

         NewImageName=${line#*,}

         if [ -e "$OldImageName" ] ; then

              mv "$OldImageName" "$NewImageName"

         #else

         #     echo "$OldImageName" >> ~/Desktop/Errors.txt

         fi

    done <"$2"

  • by Mark Jalbert,

    Mark Jalbert Mark Jalbert Feb 1, 2014 9:04 AM in response to userremoved
    Level 5 (4,649 points)
    Feb 1, 2014 9:04 AM in response to userremoved

    “Ditch_Witch_SK_300.jpg%0D” has failed to upload due to an error

    Sorry, this file type is not permitted for security reasons.

    You have Window's line endings in your csv file. You need to replace the CRLF characters with the unix newline character.

  • by Tony T1,

    Tony T1 Tony T1 Feb 1, 2014 9:39 AM in response to userremoved
    Level 6 (9,249 points)
    Mac OS X
    Feb 1, 2014 9:39 AM in response to userremoved

    kittersa wrote:

     

    There is something that happens during the Automator that changes the .jpg file. They cannot be loaded into Wordpress I get an error message saying:

     

    “Ditch_Witch_SK_300.jpg%0D” has failed to upload due to an error

    Sorry, this file type is not permitted for security reasons.

     

    Hmm.... %OD is a carriage return, so we'll use tr to get rid of it with:

         NewImageName=$( echo "$NewImageName" | tr -d '\r' )

     

    Try:

     

    cd "$1"

    while read line     

    do     

         OldImageName=${line%,*}

         NewImageName=${line#*,}

         NewImageName=$( echo "$NewImageName" | tr -d '\r' )

         if [ -e "$OldImageName" ] ; then

              mv "$OldImageName" "$NewImageName"

         else

              echo "$OldImageName" >> ~/Desktop/Errors.txt

         fi

    done <"$2"

  • by userremoved,

    userremoved userremoved Dec 27, 2015 4:28 PM in response to Tony T1
    Level 1 (0 points)
    Dec 27, 2015 4:28 PM in response to Tony T1

    Amazing as always.

     

    In Numbers you wouldn't know how to add text in front of a word rather than at the end?

     

    For example:

     

    Ditch_Witch_SK_300.jpg > wp-content/uploads/2014/02/Ditch_Witch_SK_300.jpg

     

    Much appreciated

  • by Tony T1,

    Tony T1 Tony T1 Feb 3, 2014 6:21 AM in response to userremoved
    Level 6 (9,249 points)
    Mac OS X
    Feb 3, 2014 6:21 AM in response to userremoved

    In Numbers you wouldn't know how to add text in front of a word rather than at the end?

     

    In Numbers,

    enter "wp-content/uploads/2014/02/Ditch_Witch_SK_300.jpg" in the column next to "Ditch_Witch_SK_300.jpg" and then in the 3rd column enter: =C3&B3  (the & concatenates the 2 strings):

     

    Screen Shot 2014-02-03 at 9.12.30 AM.png

     

    You can then convert the formula in col D to the concatenate string by selecting the column, copy (⌘C), then Paste Formula Results (⇧⌘V). and delete col B and C

  • by Tony T1,

    Tony T1 Tony T1 Feb 3, 2014 7:38 AM in response to Tony T1
    Level 6 (9,249 points)
    Mac OS X
    Feb 3, 2014 7:38 AM in response to Tony T1

    edit: s/b :

    enter "wp-content/uploads/2014/02/" in the column next to "Ditch_Witch_SK_300.jpg" and then in the 3rd column enter: =C3&B3  (the & concatenates the 2 strings):

  • by bj49wd,

    bj49wd bj49wd Mar 26, 2014 10:44 AM in response to Tony T1
    Level 1 (29 points)
    Notebooks
    Mar 26, 2014 10:44 AM in response to Tony T1

    I really appreciate this thread. I'm trying to do something similar with .wav files. I have a CSV with col 1 being a non-descript filename (HiFe_345.wav) and I want to give it a familiar name (CrowCall_02.wav) which is listed in col 2 in my CSV file. 

     

    I've set up an Automator Workflow with the Shell Script as shown.

     

    It ran perfectly... except, all my .wav files are now considered "documents" and won't open/play.

    Screen Shot 2014-03-26 at 10.39.29 AM.pngbecomes Screen Shot 2014-03-26 at 10.40.12 AM.png

     

    If I manually delete the .wav extension and retype ".wav", Finder prompts me to confirm I want to change the filetype. Should I not include the file type extension in the familiar name column in my CSV? There are way too many files to manually change all the extensions... do I need to run another automator workflow?

  • by Tony T1,

    Tony T1 Tony T1 Mar 26, 2014 11:40 AM in response to bj49wd
    Level 6 (9,249 points)
    Mac OS X
    Mar 26, 2014 11:40 AM in response to bj49wd

    Check that there are no spaces in the files ext (i.e. "wav ")

  • by bj49wd,

    bj49wd bj49wd Mar 26, 2014 12:42 PM in response to Tony T1
    Level 1 (29 points)
    Notebooks
    Mar 26, 2014 12:42 PM in response to Tony T1

    Thanks Tony,

    No spaces. I tried adding a rename file extension task to the workflow.... but it still produces a "document".

    Manually changing the extension properly restores the file to a working .wav file. Strange.

Previous Page 2 of 11 last Next