开发者

What is the 'on quit' handler used for?

I know all of the basic handlers, i.e. on run, on open, and on 开发者_开发知识库reopen. But this handler, on quit, confuses me. My questions are, what is it used for and how is it triggered?


on quit is used in scripts that have been saved as a standalone application. The user can quit such a script using its menus. A quit handler runs when the user quits the script, and can put up a confirmation dialog asking if they are sure they really want to quit, or clean up any temporary files it created, etc. -- anything the script needs to do before it ends. When you have finished doing whatever it is you want to do, continue quit to actually allow the script to exit.

Often used with an on idle handler, as scripts with such a handler can stay open for long periods of time and the user may need some way to exit them.


on quit is a function that allows you to do something on quit. To trigger it, simply use quit. For example, if I wanted to say to the user "Thanks for trying this!" then I'd do this:

--lots of code, blah blah
quit

on quit
display dialog "Thanks for trying this!" buttons {"Continue"}
continue quit
end

Which would display a dialog, then it would continue quitting. But, if I wanted to cancel quit, I'd remove the continue quit line.

Hopefully this should make sense.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜