Re: Quit Command from a Script Menu
Re: Quit Command from a Script Menu
- Subject: Re: Quit Command from a Script Menu
- From: Matthew Smith <email@hidden>
- Date: Tue, 06 Jul 2004 10:54:57 +1000
on 05/07/2004 07:12, email@hidden at email@hidden wrote:
>
I have the attached script that I would like to run from an application's
>
Script Menu (in this case, Claris Emailer). What I am trying to do is
>
skip execution of handlers 2 and 3 if an error occurrs in handler 1. It
>
works fine when running as a stand alone script, but when I try to run it
>
from a script menu, the application gets the quit message instead of the
>
script... and, after the application quits, handlers 2 and 3 run.
>
>
I realize I could have the handlers return pass/fail values and bypass
>
the following ones with a test, but that get's really tedious with a
>
large number of handlers.
>
>
My objective is write a script that will catch fatal errors such as
>
timeouts, etc. and gracefully terminate, closing open files, updating
>
stored variables, etc.
>
>
Any suggestions for how to accomplish this?
This is where you can use AppleScript's try/error handling mechanism.
See
<
http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScript
LangGuide/index.html> for more details.
See changes below:
>
----- Attached Script ---------
>
>
>
on handler_1()
>
display dialog "Executing Handler 1"
>
--abort()
error -128
>
return
-- placing a return at the end of a handler is not necessary
-- it will return automatically
>
end handler_1
>
>
on handler_2()
>
display dialog "Executing Handler 2"
>
return
>
end handler_2
>
>
on handler_3()
>
display dialog "Executing Handler 3"
>
return
>
end handler_3
>
>
on abort()
>
display dialog "Quitting"
>
-- If run standalone, handlers 2 & 3 won't be executed.
>
-- However, either quit form below results in Emailer quitting and the
>
script
>
-- continuing to run when run from the Emailer Script Menu
>
quit
>
tell me to quit
>
end abort
>
>
-->>Main Script<<
>
try
>
handler_1()
>
handler_2()
>
handler_3()
On error -128
-- this is the user cancelled error message
-- this error is also sent when a user presses the cancel button on a
-- display dialog window or other user interaction
End try
--
Matthew Smith
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.