I have an AppleScript that runs on images selected in the Finder. I’m trying to make an Automator service with it so I can right click on the images and run it as a service, but I’m having trouble getting it working. Here’s the script:
set theFolder to (path to desktop folder as text) & "Packaged Retina TIFFs:"
tell application "Finder"
set theItems to selection as alias list
if exists folder theFolder then
(* do nothing *)
else
make new folder at (path to desktop folder as text) with properties {name:"Packaged Retina TIFFs"}
end if
end tell
repeat with anItem in theItems
set standardImage to contents of anItem
tell application "System Events" to set {name:fileName, name extension:nameExtension, container:parentFolder} to standardImage
if nameExtension is missing value then set nameExtension to ""
if nameExtension is not "" then set fileName to text 1 thru ((count fileName) - (count nameExtension) - 1) of fileName
set retinaImage to (path of parentFolder) & fileName & "@2x." & nameExtension
try
retinaImage as alias -- test if @2x file exists
set combinedTIFF to POSIX path of (path to desktop folder) & "Packaged Retina TIFFs/" & fileName & "_retina.tiff"
--set combinedTIFF to POSIX path of theFolder2 & fileName & "_retina.tiff"
do shell script "tiffutil -cathidpicheck" & space & quoted form of POSIX path of standardImage & space & quoted form of POSIX path of retinaImage & space & "-out" & space & quoted form of combinedTIFF
end try
end repeat
When I select some images and run the service it says “The action “Run AppleScript” encountered an error”. Any ideas on what I should do to make it work?
I would wrap it in an error handler to see if I could get more information that way …
try
set theFolder to (path to desktop folder as text) & "Packaged Retina TIFFs:"
tell application "Finder"
set theItems to selection as alias list
if exists folder theFolder then
(* do nothing *)
else
make new folder at (path to desktop folder as text) with properties {name:"Packaged Retina TIFFs"}
end if
end tell
repeat with anItem in theItems
set standardImage to contents of anItem
tell application "System Events" to set {name:fileName, name extension:nameExtension, container:parentFolder} to standardImage
if nameExtension is missing value then set nameExtension to ""
if nameExtension is not "" then set fileName to text 1 thru ((count fileName) - (count nameExtension) - 1) of fileName
set retinaImage to (path of parentFolder) & fileName & "@2x." & nameExtension
try
retinaImage as alias -- test if @2x file exists
set combinedTIFF to POSIX path of (path to desktop folder) & "Packaged Retina TIFFs/" & fileName & "_retina.tiff"
--set combinedTIFF to POSIX path of theFolder2 & fileName & "_retina.tiff"
do shell script "tiffutil -cathidpicheck" & space & quoted form of POSIX path of standardImage & space & quoted form of POSIX path of retinaImage & space & "-out" & space & quoted form of combinedTIFF
end try
end repeat
on error errMsg number errNum
tell me
activate
display alert errMsg & return & return & "Error number" & errNum buttons "Cancel"
end tell
end try