3 Replies Latest reply: Apr 25, 2011 10:40 AM by Camelot
David Gordon Level 1 Level 1 (115 points)

I have an AppleScript which involves the user selecting a folder for images to be exported to (from Aperture). Later I need to run a shell script on the images in that folder. I had help at https://discussions.apple.com/thread/3012302 to get the shell script running. Currently Aperture exports the images but the script runs with an error

 

error "No file specified" number 1

 

suggesting I haven't said which folder to use.

 

So I believe I need to "tell FInder" the location of the folder chosen by System Events. If so how do I go about passing the name and location of my 'exportFolder' to application Finder? Or do you think something else is causing the error?

 

Script below, many thanks!

 

-- Creating a new filename by making Version Name  from the IPTC Headline and Filename (with hypens where spaces exist). The Aperture Version Name is used to create the file's name on export. Once exported the Aperture Version Name is reset to its original.

 

tell application "System Events"

          set exportFolder to (choose folder with prompt "Choose an export folder")

end tell

 

 

tell application "Aperture"

          set theSel to (get selection)

          if theSel is {} then

                    error "Please select an image or two!."

          else

                    repeat with theImg in theSel

 

  -- Creating a new Aperture Version Name which will become the exported file's filename.

 

                              tell theImg

                                        set headline to (get value of IPTC tag "Headline" of theImg)

                                        set AppleScript's text item delimiters to " "

                                        set theTextItems to text items of headline

                                        set AppleScript's text item delimiters to "-"

                                        set headline to theTextItems as string

                                        set AppleScript's text item delimiters to {""}

                                        set objectName to (get value of IPTC tag "ObjectName" of theImg)

                                        set newVersion to (headline & "-" & objectName) as string

                                        set name of theImg to newVersion

                              end tell

                    end repeat

 

  -- Exporting the files as JPEGs to chosen folder/Project Name using the Version Name as a filename

 

                    export theSel using export setting "JPEG - Original Size" to exportFolder


  -- Resetting the Aperture Version Name back to filename using IPTC Title (which should be the file's filename without suffex).

 

                    repeat with theImg in theSel

                              tell theImg

                                        set title to (get value of IPTC tag "ObjectName" of theImg)

                                        set name of theImg to title

                              end tell

                    end repeat

 

          end if

end tell

 

--Using ExifTool to set Photoshop Copyright Status and fiddle some EXIF camera data

 

tell application "Finder" to set theFiles to files of exportFolder as alias list

repeat with eachFile in theFiles

          do shell script "/usr/bin/exiftool -overwrite_original -Photoshop:CopyrightFlag='True' -Photoshop:URL='http://davidgordon.co.uk/'" & quoted form of POSIX path of theFiles

 

end repeat

display dialog "Done that!" with icon note buttons "OK" default button 1 giving up after 10

  • David Gordon Level 1 Level 1 (115 points)

    Just to clarify the above - the script does export the image from Aperture to the chosen folder. The ExifTool shell script does not run.

     

    Thanks!

  • red_menace Level 6 Level 6 (14,760 points)

    Looks like you just got your variables mixed up in the ExifTool shell script.  In your repeat loop, theFiles is a list of the files in your folder, while eachFile is the individual item you need to pass to the shell (you can't get the POSIX path of the list).

  • Camelot Level 8 Level 8 (46,195 points)

    In addition to Red's (correct) analysis, you're also missing a space in the exiftool command parameters:

     

              do shell script "/usr/bin/exiftool -overwrite_original -Photoshop:CopyrightFlag='True' -Photoshop:URL='http://davidgordon.co.uk/'" & quoted form of POSIX path of theFiles

     

    Note that you're appending the POSIX path of the file (or, as per Red's note, eachFile) directly after the 'Photoshop:URL' parameter. Since there's no space the shell will interpret these two elements as one and you'll end up with something like:

     

    -Photoshop:URL='http://davidgordon.com.uk'/path/to/the.jpeg

     

    which is guaranteed to fail.

     

    The solution is simple - trivial, even... include a space between the Photoshop:URL parameter and the path, like:

     

              do shell script "/usr/bin/exiftool -overwrite_original -Photoshop:CopyrightFlag='True' -Photoshop:URL='http://davidgordon.co.uk/' " & quoted form of POSIX path of eachFile

     

    (note the space after the quoted URL, and before the appended path)