Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

FastScripts quitting on script error?

edited May 2009 in FastScripts
I use a script to manipulate images on the clipboard that I run from a FastScripts shortcut key.

When the script runs it checks for the existence of a TIFF image in the clipboard. If not found, the script displays a dialog and quits (because it can't do anything without an image to work on).

But Fastscripts ALSO quits, damnit! Why? No doubt my fault but I can't figure this out. So I'd much appreciate any thoughts from the more code-literate. I attach the code of the script below.

The offending (?) quit statement is near the top. I've tried this slightly odd formulation ('tell me to continue quit') in an attempt to avoid confusing the applescript engine about what to terminate. But it doesn't stop the termination of FastScripts.


--
-- Make a JPG image and Thumbnail on the Desktop
-- Input: TIFF image in the clipboard
-- Outputs: 2 JPG image files on Desktop (resized image and thumbnail)
-- Expects: Installation of ImageMagick
--
-- www.petergallagher.com.au :: March 2009 :: No rights claimed
--
on bailout()
tell me to continue quit
end bailout

on run
set tp to 0
repeat with i in clipboard info
if TIFF picture is in i then
set tp to the clipboard as TIFF picture
exit repeat
else
display dialog \"No TIFF in clipboard\"
bailout()
end if
end repeat
if tp is not 0 then
set dt to current date
set ex to \".tiff\"
set dtstr to (time of dt as string)
set pt to ((path to temporary items from user domain as string) & dtstr & ex)
set tf to open for access file pt with write permission
try
write tp to tf
close access tf
on error
close access tf
end try
try
tell me to convertIt((the quoted form of the POSIX path of pt), (the quoted form of the POSIX path of ((path to desktop folder as string) & dtstr & \".jpg\")))
tell me to makeThumb((POSIX path of (path to desktop folder as string)), dtstr)
on error errMsg
display dialog errMsg
quit
end try
end if
end run

on convertIt(theFilePath, theFileName)
set myConvScript to ¬
\"/opt/local/bin/convert -filter Lanczos -strip -resize 'x600>' -sigmoidal-contrast 1,50 -unsharp 0.5x0.5+0.2+0.0 -quality 75 \" & theFilePath & \" \" & theFileName
try
do shell script (myConvScript)
on error errMsg
display dialog errMsg
end try
end convertIt

on makeThumb(theFilePath, theFileName)
set myThumbScript to \"/opt/local/bin/convert -strip -resize 'x100>' -sigmoidal-contrast 1,50 -unsharp 0.5x0.5+0.5+0.0 \" & theFilePath & theFileName & \".jpg\" & \" \" & theFilePath & theFileName & \"_tmb.jpg\"
try
do shell script (myThumbScript)
on error errMsg
display dialog errMsg
quit
end try
end makeThumb

Comments

  • I think I see what is going on. When a script is run by another application, e.g. FastScripts, the script itself doesn't have a concept of "quit" ... so the quit command gets passed on to FastScripts.

    You probably want to remove the "tell me to continue quit" line ... just replacing that bailout() line with "return" would probably be sufficient.

    Hope that helps,

    Daniel
  • Thanks for the quick response and advice Daniel.

    As you suggest, commenting out the 'quit' or 'bailout()' line in the main loop solves the problem.

    Can I assume that its ... um, good sanitation practice to allow the 'run' routine to just end in an indeterminate state without being terminated by the 'quit' statement?

    I have another script that I run regularly from FastScripts that also uses an 'on quit' statement because it runs essentially in an 'on idle' loop. That script does NOT cause FastScripts to quit. But the difference may be that I'm running it in a compiled form (as an Applescript application) from FastScripts (?)

    BTW.. FastScripts is an essential tool for me. I see that it doesn't seem to get a lot of forum action. But I'm a big fan.

    Best,

    Peter
  • Yeah - it's normal for a script to "just return" ... the runner of the script, FastScripts in this case, chooses whether to display an error or not based on the way it returns. So if you wanted to, instead of "return" you could do something like 'error "Whoops!"' and FastScripts should display it for you...

    Glad you like FastScripts! It's definitely a bit of a hacker tool, but those who like it tend to REALLY like it so that's gratifying for me! :)

    Daniel
  • Daniel Jalkut said:
    So if you wanted to, instead of "return" you could do something like 'error "Whoops!"' and FastScripts should display it for you...
    Hey! You know I didn't know that! That's great, because the error dialog allows me to edit the script.

    Thanks,

    Peter
  • It's taken years for me to learn what I do know about AppleScript, and even still I feel like a complete novice!
Sign In or Register to comment.