Re: Quit Handler... What Am I Missing Here?
Re: Quit Handler... What Am I Missing Here?
- Subject: Re: Quit Handler... What Am I Missing Here?
- From: "S. J. Cunningham" <email@hidden>
- Date: Thu, 12 May 2011 08:06:32 -0400
Forgive the top post, but I am apparently still not asking my question clearly. Let me try again :-)
I have a script compiled as an application which runs in an infinite loop, checking a website for changes every so often (Woot during a Woot-Off, if you must know). Like a total noob, I assumed that if I selected "Quit" from the running script's application menu, it would execute the quit handler and, well, quit. It doesn't. The only way I can quit the application is to Force Quit it and that leaves files open that the quit handler was supposed to clean up. This seems like a bug to me.
It also seems inconsistent with the behavior described in the Applescript Language Guide,
http://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_about_handlers.html
In particular the guide gives the following example:
on quit
display dialog "Really quit?" ¬
buttons {"No", "Quit"} default button "Quit"
if the button returned of the result is "Quit" then
continue quit
end if
-- Without the continue statement, the application doesn't quit.
end quit
... Implying that it _will_quit_ if the continue statement _is_ present. This was the example I used in my original post.
Can someone please explain the function of the "Quit" command in the application menu if it is not to quit the application? And what is the purpose of a quit handler which can't be called other than in a script which doesn't have an explicit run handler. I could just put the stuff I wanted to do at the end of the script.
I used to write a lot of scripts in earlier versions of the OS and I am sure that "quit" didn't behave like this but in the more intuitive fashion which I expected.
Thanks
On May 12, 2011, at 7:03 AM, Nigel Garvey wrote:
> "S. J. Cunningham" wrote on Wed, 11 May 2011 11:58:37 -0400:
>
>> OS X 10.6.7. I want to run a script as an application but I can't seem to
>> get the quit handler to quit. Seems to me it used to work this way but
>> maybe my memory is faulty. Or maybe Snow Leopard changed something.
>> Anyway, here is the sample script I am running. I get the same behavior
>> with an implicit run handler. Help appreciated.
>>
>> Thanks.
>>
>> (*
>> Quit Handler Example Case 1: Explicit run handler
>>
>> - Works as expected when run from Script Menu as either
>> Compiled Data Fork or Compiled Bundle
>> - Continue quit ignored when run as an Application Bundle
>> either from Finder or Script Menu.
>> *)
>>
>> on run {}
>> display dialog "Quit Handler Example Case 1: explicit run handler"
>> display dialog "Calling quit handler"
>> quit
>> display dialog "Whoops! Statement following quit in run handler"
>> end run
>
> The 'quit' command tells the application running the script to quit when
> it's finished what it's doing — ie. running the script. Since you have
> another command after the 'quit', that command will be executed before
> the application actually does quit.
>
> If you want to stop a script on the spot, use 'error number -128'
> instead. If it's running as a non stay-open application, it'll quit then
> of it's own accord.
>
>> on quit {}
>> display dialog "quit handler entered"
>> try
>> set dialogAnswer to display dialog ¬
>> "Continue quit?" buttons {"Yes", "No", "Cancel"} ¬
>> default button "Yes"
>> if button returned of dialogAnswer is "Yes" then
>> display dialog "continuing quit"
>> continue quit
>> display dialog "Statement following continue quit"
>> else
>> -- your code for No goes here
>> end if
>> on error number -128 -- userCanceledErr
>> -- your code for Cancel goes here
>> end try
>> display dialog "Exiting quit handler"
>> end quit
>
> Similarly here you have two 'display dialog' commands after 'continue
> quit', so these must be executed before the application can quit.
>
> NG _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden