Friday, January 19, 2018
  • Index
  •  » Automator
  •  » Get an AppleScript to run as an Automator service?

#1 2012-08-30 09:20:51 am

Jono
Member
Registered: 2008-07-08
Posts: 64

Get an AppleScript to run as an Automator service?

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:

Applescript:

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?


Filed under: applescript

Offline

 

#2 2012-08-30 11:22:38 am

adayzdone
Member
From:: New York
Registered: 2011-01-25
Posts: 525

Re: Get an AppleScript to run as an Automator service?

I would wrap it in an error handler to see if I could get more information that way ...

Applescript:


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

Offline

 

#3 2012-08-30 03:59:28 pm

Jono
Member
Registered: 2008-07-08
Posts: 64

Re: Get an AppleScript to run as an Automator service?

Thanks for the help. When I use the updated script and run it the error message says:

System Events got an error: Can't get path of folder "Macintosh HD:Users:Jono:Desktop:"
Error number-1728


I'm not sure why it has a problem with the path. Any ideas of what could be wrong?

Offline

 
  • Index
  •  » Automator
  •  » Get an AppleScript to run as an Automator service?

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)