• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How do you get a stay-open applet to quit?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you get a stay-open applet to quit?


  • Subject: Re: How do you get a stay-open applet to quit?
  • From: kai <email@hidden>
  • Date: Mon, 2 Jan 2006 16:20:28 +0000


On 2 Jan 2006, at 01:14, Michelle Steiner wrote:

On Jan 1, 2006, at 6:07 PM, Adam Bell wrote:

You want "exit repeat" - the script will quit itself when there's
nothing left to do

That didn't quit the script either. However, by doing that and unchecking "stay open" it lets it quit.


That solves my immediate problem, but doesn't solve the--now academic--problem of how to make a stay-open applet quit.

There are a few issues here, Michelle. Individually, each may be considered simple enough. But when they're combined, it can sometimes be harder to see the wood for the trees (so I hope you'll forgive me if any of the following might STBO).


Firstly (as we've already seen), while there's an implicit quit command in a regular script application, a stay-open applet requires an explicit one. In either case, the script has to finish running (one way or another) before the quit command can be executed.

Secondly, hitting the "Cancel" button of a dialog generates an error number -128 - which, if not trapped, halts execution of the script. If this occurs in a regular script application, the implicit quit command is invoked anyway. With a stay-open applet, such an error would need to be trapped - so that an explicit quit command can be issued.

An alternative to error trapping is to avoid altogether the use of a button specifically labelled "Cancel". Variations might include "Exit", "Quit" - or even " Cancel " (enclosed in white space). Any of these would allow handling as a regular option.

Finally, a repeat loop ultimately requires some means of escape. This might be an exit command, a return command or an untrapped error. It could also be in the form of a condition declared upon entry - such as <repeat 2 times>, <repeat with n from 1 to 3>, <repeat with currentItem in someList> - or <repeat while/until someConditionExists>:

------------

repeat until button returned of (display dialog "Testing..." buttons ¬
	{"Done", "Repeat..."} default button 2) is "Done"

	say "repeating"

end repeat

say "done"

------------

Some simplified examples might help to demonstrate one or two of these principles.

In this next snippet, the third option (say "Help - I can't quit!") can never be executed - since clicking the "Cancel" button will halt execution of the script. When saved as a regular application, the script should routinely quit (but not when saved as a stay-open app).

------------

repeat

display dialog "Testing..." buttons {"Cancel", "Option 2", "Option 1"} default button 3
set chosenOption to button returned of result


	if chosenOption is "Option 1" then
		say "Action 1"
	else if chosenOption is "Option 2" then
		say "Action 2"
	else
		say "Help - I can't quit!"
	end if

end repeat

------------

Similarly:

------------

repeat

display dialog "Testing..." buttons {"Cancel", "Option 2", "Option 1"} default button 3
set chosenOption to button returned of result


	if chosenOption is "Option 1" then
		say "Action 1"
	else
		say "Action 2"
	end if

end repeat

say "Help - I can't quit!"

------------

However, the following should work - since it uses no "Cancel" button and an exit statement:

------------

repeat

display dialog "Testing..." buttons {"Quit", "Option 2", "Option 1"} default button 3
set chosenOption to button returned of result


	if chosenOption is "Option 1" then
		say "Action 1"
	else if chosenOption is "Option 2" then
		say "Action 2"
	else
		exit repeat
	end if

end repeat

say "Now I can quit!"
-- quit (* required for a stay-open app *)

------------

Here's an example that uses the return command:

------------

repeat

display dialog "Testing..." buttons {" Cancel ", "Option 2", "Option 1"} default button 3
set chosenOption to button returned of result


	if chosenOption is "Option 1" then
		say "Action 1"
	else if chosenOption is "Option 2" then
		say "Action 2"
	else
		return (* for a regular app *)
		-- return quit (* for a stay-open app *)
	end if

end repeat

------------

On 2 Jan 2006, at 13:41, Luther Fuller wrote:

It is possible to have a script with only an 'idle' handler and containing no commands to tell it to quit. I had one of these showing in my Dock only moments ago while reading mail. It will quit only when I choose Quit from the Dock menu. But quit will fail unless there is a 'quit' handler to receive the 'quit' message. The 'quit' handler will look like this ...

on quit
    -- optional stuff
    continue quit
end quit

Without this, it just keeps going and going ...

That's not quite my understanding or experience, Luther - which is that a script application doesn't actually require a quit handler (whether the quit command is scripted or triggered manually).


However, if *does* contain one (to carry out any pre-quit checks or routines, for example), then the quit handler in a stay-open app should include a 'continue quit' statement. If the quit handler returns or errors before it encounters a 'continue quit' statement, a stay-open application won't quit.

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >How do you get a stay-open applet to quit? (From: Michelle Steiner <email@hidden>)
 >Re: How do you get a stay-open applet to quit? (From: Adam Bell <email@hidden>)
 >Re: How do you get a stay-open applet to quit? (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: How do you get a stay-open applet to quit?
  • Next by Date: Thanks
  • Previous by thread: Re: How do you get a stay-open applet to quit?
  • Next by thread: Re: How do you get a stay-open applet to quit?
  • Index(es):
    • Date
    • Thread