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: Axel Luttgens <email@hidden>
- Date: Thu, 12 May 2011 12:25:40 +0200
Le 12 mai 2011 à 02:09, Stockly, Ed a écrit :
> [...]
>
> Here's something that works, but your app must be a stay open app.
>
> ------
> on run {}
> display alert "Starting Up"
> end run
>
> on quit {}
> display alert "About to Quit!"
> continue quit
> display alert "Trying to quit!"
> return
> end quit
>
> on idle
> return 1
> end idle
> ------
>
> Not every script can be structured with an idle handler, but if yours can,
> this will work.
Hello Ed,
Above script may be simplified so as to focus on the true point of interest:
on run
display alert "Starting Up"
end run
on quit
display alert "About to Quit!"
continue quit
display alert "Trying to quit!"
end quit
The purpose of a stay open app is, well, to stay open.
That is, instead of quitting after having performed its tasks as a regular app would do, it waits for subsequent events.
One of those events is the "quit" event.
Either there is no quit handler, and the quit event is immediately passed to the parent (the current application).
Or there is a quit handler, and that handler is invoked.
In the latter case, the quit event is trapped and won't reach the parent.
Unless the quit handler executes a "continue quit" statement, in which case the quit event is passed to the parent; the current application now has the opportunity to register that it should quit as soon as all pending tasks are performed.
> Not sure why the "Trying to quit" alert displays.
Because the quit handler, being a pending task, has to be entirely executed.
HTH,
Axel
_______________________________________________
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