Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Re-using specified folder later in an AppleScript

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 iconnotebuttons "OK" default button 1 giving up after 10

Posted on Apr 24, 2011 12:57 AM

Reply
3 replies

Apr 25, 2011 10:40 AM in response to David Gordon

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)

Re-using specified folder later in an AppleScript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.