quit handler

HI,

When an there was an error in the quit handler, back in jaguar, the stay open script used to just sit there. Now, the program seems to wait the default 30 seconds.


on idle
	quit
	return 5
end idle

on quit
	display dialog "hello"
	continue quit
end quit

When I cancel the dialog it seems like the dialog returns in 30 seconds. Is that what is happening?

Thanks,

Model: MacBook Pro
AppleScript: 2.5
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

Hi.

When you click the dialog’s Cancel button, a “User canceled.” error is generated which stops the script code from running. So:

  1. the ‘continue quit’ instruction isn’t executed and the applet doesn’t quit.
  2. the script doesn’t return from the ‘quit’ handler and execute the ‘return 5’ line, so presumably that’s why the system waits the default 30 seconds before paging the applet again.

This will preserve the 5-second interval:


on idle
	quit
	return 5
end idle

on quit
	try
		display dialog "hello"
	on error number -128 -- Catch the "User canceled." error if the Cancel button's clicked.
		return -- Return from this handler without doing anything else.
	end try
	continue quit
end quit

My Jaguar machine died a couple of years ago, so I can’t compare the behaviour now. If you actually want the applet to stay open but non-acting, the version below seems to work. It continues to be paged by the system, but doesn’t do anything while the ‘live’ variable’s set to false. You can double-click the applet icon again while the applet’s open but “switched off” and the ‘reopen’ handler will set it going again:

global live

on run
	set live to true
end run

on reopen
	set live to true
	idle
end reopen

on idle
	if (live) then
		quit
		return 5
	end if
end idle

on quit
	try
		display dialog "hello"
	on error number -128 -- Catch the "User canceled." error if the Cancel button's clicked.
		set live to false
		return -- Return from this handler without doing anything else.
	end try
	continue quit
end quit

Hello.

In addition to Nigel Garvey’s good examples, there is also a more complex snippet somewhere within the last 4-5 months or so here, if you search for quit, and idle.

Thought I’d just mention it.

Hi Nigel and McUsrII,

I’ve been reviewing the AS Language Guide and posts on this site. I’m glad Apple fixed the behavior in the quit handler.

Thanks a lot,

Model: MacBook Pro
AppleScript: 2.5
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)