2 Replies Latest reply: Feb 2, 2011 12:11 PM by rccharles
Mmiller1559 Level 1 Level 1 (0 points)
Hi All!

I have been tasked with creating a script in Automator that will enable my work to rename hundreds of photos in order to optimize new product uploading on our e-commerce site.

Essentially what we need to do is take a list of SKU product numbers and assign them to their corresponding photos. The photos names currently do not relate to the SKU number, but we do have them separated into an excel file where the first column is the new SKU name and the second column is the name of the photo that needs to be changed.

Is there any way to write a script which will enable us to pull the new SKU name and assign it to the corresponding photo that needs to be updated?

Any help would be greatly appreciated.

Macbook Pro 3,1, Mac OS X (10.6.6)
  • 1. Re: Create A Script to Rename Photos in Order
    BDAqua Level 10 Level 10 (116,475 points)
    Hi Mmiller1559, and a warm welcome to the forums!

    Maybe you can glean from this vba code hoe to do a scipt...

    Dim SourceName As String
    Dim DestName As String
    For Row = 1 To Sheets("Sheet1").Range("A65536").End(xlU…
    SourceName = Sheets("sheet1").Cells(Row, 1).Value
    DestName = Sheets("sheet1").Cells(Row, 2).Value

    Name SourceName As DestName

    Next

    http://answers.yahoo.com/question/index?qid=20081229093846AAWVBr3
  • 2. Re: Create A Script to Rename Photos in Order
    rccharles Level 5 Level 5 (5,370 points)
    Please test before using.

    Robert
    ------------------
    (* 
     excel file where the first column is the new SKU name and the second column is the name of the photo that needs to be changed.
     
    use excel to save as csv file -- comma separated
     
    example file:
    rename.csv
    a,1
    b,2
    c,3
     
    *)
    on run
       -- Write a message into the event log.
       -- To see, 
       -- Run this applescript in Sript Editor. 
       -- Click on Event Log tab at bottom of screen.
       -- Click run.
       log "  --- Starting on " & ((current date) as string) & " --- "
       
       
       -- Ask user for the name of the file
       set fileAlias to choose file with prompt "Pick the file with your list of files to rename."
       log fileAlias
       set aFile to fileAlias as text
       log "aFile = " & aFile
       
       -- Ask user for the name of the folder
       set folderAlias to choose folder with prompt "Pick the folder that contains your list of files to rename."
       log folderAlias
       set aFolder to folderAlias as text
       
       -- Based on Camelot's script in 
       -- http://discussions.apple.com/thread.jspa?threadID=2739645&tstart=0
       
       
       set files2Rename to (paragraphs of (read file aFile))
       log files2Rename
       
       
       repeat with eachFile in files2Rename
          log "eachFile = " & eachFile
          set splitData to textToList(eachFile, ",")
          
          set newName to item 1 of splitData
          set oldName to item 2 of splitData
          log "newName = " & newName & " oldName = " & oldName
          
          tell application "Finder"
             
             set actualName to aFolder & oldName
             log "actualName = " & actualName
             
             try
                -- example rename command
                -- set name of file "path:to:file" to (month of (current date)) & " " &
                --   day of (current date) & ", " & year of (current date) as string
                
                set name of file actualName to newName
                
             on error msg
                log "!!! could not rename newName = " & newName & " oldName = " & oldName
                log "!!! error was " & msg
             end try
          end tell
       end repeat
    end run
     
    -- textToList was found here:
    -- http://macscripter.net/viewtopic.php?id=15423
     
    on textToList(thisText, delim)
       set resultList to {}
       set {tid, my text item delimiters} to {my text item delimiters, delim}
       try
          set resultList to every text item of thisText
          set my text item delimiters to tid
       on error
          set my text item delimiters to tid
       end try
       return resultList
    end textToList


    -----------

    The first thing that you need to do is to make the text into an AppleScript program.

    Start the AppleScript Editor
    /Applications/AppleScript/Script Editor.app
    In Snow Leopard it's at: /Applications/Utilities/AppleScript Editor

    Copy the script text to the Applescript editor.



    Note: The ¬ is typed as option+return.It servers as a visual line end character.

    You may need to retype these characters.



    Save the text to a file as an application and do not check any of the boxes below.
    !http://farm4.static.flickr.com/3544/3390737677_645a847e28.jpg?v=0!
    If you want access to the script from your Script Menu, move the script (the saved script application file) to your
    ~/Library/Scripts folder. You can also drag it to your Dock or make an alias for it on the Desktop.



    To debug, run the script within the Applescript Editor. Click on the event log tab at the bottom of the window. Click on the run icon. The results from the log statement will be shown at the bottom of the screen.
    !http://farm5.static.flickr.com/4029/4690586217_1f57b5a2f5.jpg!

    ---------------