quit issues

i’ve some problem with choose file, used into a repeat loop.

If i cancel the choose file action at some point inside the repeat-loop, (because i want to select anything), the repeat handler simply quits. Here it quits and it shouldn’t !

another situation is when i code for stay-open apps. Here, the quit commands seems not to work, exactly the opposite as described above.
Honesty, i never figured out how to control effectively quit commands in stay-open apps. (Not that i write stay-open apps every day)
I used return, tell me to quit, continue quit, on quit handler, but nothing helps. I’ve had success in some stay-open apps and they quit correctly, but in others not. Its frustrating for me for some time now.

Maybe its the hierarchy of handlers which counts, but i think not. My handlers are not too big, and i use relative few repeats, but more often if-handlers.
some hints?

Hi,

consider that pressing Cancel in the open/save dialog window throws an User Cancelled error (-128),
which aborts a plain script unless the choose file statement is within a try block

try
	choose file
on error e number n
	display dialog e & " (" & n & ")" --> User cancelled (-128)
end try

in a stay open script the normal way is to implement the on quit handler and call it with the quit command


on quit
	-- do some cleaning up
	continue quit
end quit

Hi Stefan

fine! sometimes little problems seems bigger than others.
For idle handlers:
you say, its better to quit an stay-open app instead to insert quit commands here and there between the handlers?
i used to code quit commands in different handlers too (like: on reopen). Maybe in those who dislike to quit? :slight_smile:

on reopen
	set my_but to choose from list ls2 with prompt "PAUSE" 

	set quit_y to false
if my_but is "Beenden" then
		set quit_y to true
else
--some statements
end

if quit_y is true then tell me to quit
end reopen

your example cannot work because of a different reason.
Choose from list returns always a list of the selected items even there is only one
or boolean false if Cancel has been pressed


on reopen
	set my_but to choose from list ls2 with prompt "PAUSE"
	if my_but is false then
		-- do something if the user pressses Cancel
	end if
	set quit_y to false
	if (item 1 of my_but) is "Beenden" then -- item is needed because my_but is a list
		set quit_y to true
	else
		--some statements
	end if
	
	if quit_y is true then tell me to quit
end reopen

Ops, sorry,

i forgot to paste yet:

on reopen
set quit_y to false
set ls2 to ("Option1","Abort")
set my_but to choose from list ls2 with prompt "PAUSE"

if my_but is false then return --user cancelled
set my_but to my_but as text

--the rest
 if my_but is "Abort" then
        set quit_y to true
else

end
   if quit_y is true then tell me to quit
end reopen

it doesn’t work, seems strange but it is so. (Consider always its Inside a stay-open script)

If it’s inside a stay open script then you must use a quit handler.

Yes and no,
its difficult to say- Adam. It may depend on different Operating systems. I’m quite sure on this. I managed to quit an open-stay application using other handlers as well than the quit handler itself, which works always fine. (if not for other reasons like between asserted above) Because i work with leo on an ibook and snow leo on my imac.
The scripts i code, compile and run behave quite different between version 10.5 and 10.6. By the way, not that i’m unhappy of the progression, but in this case problems are inevitable and a bit annoyingly.
thanks for the tips.
jo

in a stay open script I recommend to use extra handlers for the code
which does not belong directly to the event handlers


on reopen
	checkOptions()
end reopen

on quit
	continue quit
end quit

on checkOptions()
	set quit_y to false
	set ls2 to {"Option1", "Abort"}
	set my_but to choose from list ls2 with prompt "PAUSE"
	
	if my_but is false then quit --user cancelled
	set my_but to item 1 of my_but
	
	--the rest
	if my_but is "Abort" then
		set quit_y to true
	else
		
	end if
	if quit_y is true then quit
end checkOptions

The reason for different behavior in different operating systems could be also syntax issues
which were actually not correct but silently tolerated in older systems