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

first Previous Page 4 of 11 last Next
  • by bj49wd,

    bj49wd bj49wd Apr 1, 2014 4:07 PM in response to Tony T1
    Level 1 (29 points)
    Notebooks
    Apr 1, 2014 4:07 PM in response to Tony T1

    Interesting... the original spreadsheet did come from an external source, most likely Excel and then was delivered to me via Google Docs... and then I messed with it in Numbers... I wonder if there's a "Show Invisible Characters" feature in Numbers...?

     

    Thanks again!

  • by kmgold,

    kmgold kmgold May 4, 2014 1:04 PM in response to Tony T1
    Level 1 (0 points)
    May 4, 2014 1:04 PM in response to Tony T1

    Hi, Sorry to add to this thread, but I'm strapped for time and I need assistance with the scripts described here; I am not able to get any of them to work. My situation is almost identical: The images are in a folder called "images" on my desktop (~/Desktop/images) and the csv file is contained within it (~/Desktop/images/SND.csv)

     

    csvdocimage.png

     

    So, for example in line 1:I would like the file named 0031.jpg to be changed to 31-Dallas Morning News.jpg. I've been at this problem for a while, so any assistance would be greatly appreciate it.

  • by Tony T1,

    Tony T1 Tony T1 May 4, 2014 1:24 PM in response to kmgold
    Level 6 (9,249 points)
    Mac OS X
    May 4, 2014 1:24 PM in response to kmgold

    The 1st bash script listed here should work:

     

         #!/bin/bash

     

         cd ~/Documents/images

         while read line         

         do         

              OldImageName=${line%,*}

              NewImageName=${line#*,}

              mv "$OldImageName" "$NewImageName"

         done <"SND.csv"

     

    As is does not, try this, then post a few lines of the error.txt file that will be created on the Desktop

     

    #!/bin/bash
    
    
    cd ~/Documents/images
    while read line          
    do          
         OldImageName=${line%,*}
         NewImageName=${line#*,}
         echo mv "$OldImageName" "$NewImageName" >> ~/Desktop/error.txt
    done <"SND.csv"
    



  • by kmgold,

    kmgold kmgold May 4, 2014 4:23 PM in response to Tony T1
    Level 1 (0 points)
    May 4, 2014 4:23 PM in response to Tony T1

    Thanks for the prompt reply.

     

    Originally, when running the script, there was no error, but there was no affect on any of the images.

     

    On a second try, I omitted the first line cd ~/[Desktop]/images and tried saving the script in the folder with everything else and running it from there. At that point, I get a "while: bad interpreter: No such file or directory" error message in the terminal.

     

    Nothing shows on the desktop at either point.

     

    Perhaps I am executing the script incorrectly?

     

    I used SublimeText to create a new script, which i called "rename.sh." I then navigated to it's directory, changed the permissions using the following command: "chmod +x ./rename.sh." I then ran it using the "./rename.sh" command.

     

    Let me know if you need further details and thanks again.

  • by Tony T1,

    Tony T1 Tony T1 May 4, 2014 5:23 PM in response to kmgold
    Level 6 (9,249 points)
    Mac OS X
    May 4, 2014 5:23 PM in response to kmgold

    Make sure that the 1st line in the script is:

          #!/bin/bash

     

    If it still doen not work, try using TextEdit and save as a Plain Text File

    (TextEdit->Format->Make Plan Text)

    If it still does not work, in Terminal, what do you get when you run: which bash

  • by kmgold,

    kmgold kmgold May 5, 2014 8:29 AM in response to Tony T1
    Level 1 (0 points)
    May 5, 2014 8:29 AM in response to Tony T1

    Still not working; when I run the script from the desktop directory, I get no errors and no affect on the images in the folder.

     

    When the script is run from the images directory, I get the following, based on whether or not I include the first (second after #!/bin/bash) line.

     

    cd: bad interpreter: No such file or directory

    -or-

    while: bad interpreter: No such file or directory

     

    which bash yields "/bin/bash"

  • by Tony T1,

    Tony T1 Tony T1 May 5, 2014 8:47 AM in response to kmgold
    Level 6 (9,249 points)
    Mac OS X
    May 5, 2014 8:47 AM in response to kmgold

    Try to run from Applescript.

    Copy this to Apple Script Editor, and click [Run]

    Also click [Result] at the bottom of AppleScript Editor to show any errors:

     

    do shell script "
    cd ~/Desktop/images
    while read line          
    do          
         OldImageName=${line%,*}
         NewImageName=${line#*,}
         mv \"$OldImageName\" \"$NewImageName\"
    done < \"SND.csv\"
    "
    

     

     

              Screen Shot 2014-05-05 at 11.44.20 AM.png

  • by kmgold,

    kmgold kmgold May 5, 2014 9:01 AM in response to Tony T1
    Level 1 (0 points)
    May 5, 2014 9:01 AM in response to Tony T1

    ""

     

    The above is what shows in "Result" when run as an AppleScript - still no effects on the image files.

     

    Could it be a permissions issue on the image files themselves? I have Read & Write access to each image but "Everyone" and "staff" has Read only permission.

  • by Tony T1,

    Tony T1 Tony T1 May 5, 2014 9:17 AM in response to kmgold
    Level 6 (9,249 points)
    Mac OS X
    May 5, 2014 9:17 AM in response to kmgold

    Try this in AppleScript, and post the first few lines of what's created in the file error.txt on the desktop:

     

    do shell script "
    cd ~/Desktop/images
    while read line         
    do         
         OldImageName=${line%,*}
         NewImageName=${line#*,}
         echo mv \"$OldImageName\" \"$NewImageName\" >> ~/Desktop/error.txt
    done < \"SND.csv\"
    "

  • by Amosiko,

    Amosiko Amosiko May 21, 2014 1:20 PM in response to Tony T1
    Level 1 (0 points)
    May 21, 2014 1:20 PM in response to Tony T1

    Hi Tony,

     

    I have tried the Automater but for whatever reason I can't get it to work. It says the workflow is complete and nothing changes with file name for the images does not change.

  • by Tony T1,

    Tony T1 Tony T1 May 21, 2014 1:39 PM in response to Amosiko
    Level 6 (9,249 points)
    Mac OS X
    May 21, 2014 1:39 PM in response to Amosiko

    Are you sure your CSV file is the same format as the OP?

    Post a screenshot of your CSV file.

  • by Amosiko,

    Amosiko Amosiko May 21, 2014 1:43 PM in response to Tony T1
    Level 1 (0 points)
    May 21, 2014 1:43 PM in response to Tony T1

    Thank you for the quick reply.

     

    This is just a test of the CSV to get it going before I attempt the 1000+ files. Screen Shot 2014-05-21 at 3.41.52 PM.png

  • by Amosiko,

    Amosiko Amosiko May 21, 2014 1:44 PM in response to Amosiko
    Level 1 (0 points)
    May 21, 2014 1:44 PM in response to Amosiko

    This is the Run Shell Script I am using:

     

    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 Tony T1,

    Tony T1 Tony T1 May 21, 2014 1:48 PM in response to Amosiko
    Level 6 (9,249 points)
    Mac OS X
    May 21, 2014 1:48 PM in response to Amosiko

    Are you getting an Error.txt file on the Desktop?

  • by Amosiko,

    Amosiko Amosiko May 21, 2014 1:49 PM in response to Tony T1
    Level 1 (0 points)
    May 21, 2014 1:49 PM in response to Tony T1

    I am but it comes across as jiberish unforntantly.

first Previous Page 4 of 11 last Next