(* Save this as an Application, Stay-Open This script puts off quitting until the run procedure has completed. So it seems that to get a script to quit, control has to be released from any procedures. It's as if there's an overseer that decides which event handler to call. And that overseer won't interrupt an event handler to call the quit handler. So this is done in the run handler by giving up control by "return"-ing as soon as the quit event has been issued. *) on run try display dialog "We'll quit now, OK?" buttons "Cancel" on error tell me to quit return -- this ensures that no more events are generated by the run handler end try tell me to saySomething() tell me to activate end run on saySomething() say "Something" end saySomething on quit say "By" -- this is performed when the quit is called, -- but for this to be carried out, any remaining events must be handled continue quit end quit on idle beep return 1 end idle on activate beep beep delay 2 beep delay 1 beep end activate