Display Dialogue with a Countdown?

Hello Again!

I am ‘perfecting’ my backup script and would like to allow for the script to pause if the user is still up for some ungodly reason at 1AM. However, if they’re not, the dialogue would only stay up for a certain amount of time and then continue on with the rest of the script. Here is my initial try:


repeat
	set button_result to (display dialog "The Backup Script is ready to run.  All applications will close and be unavailable for approximately 5 minutes.  Click OK to run or DELAY to postpone this operation 1 Hour." buttons {"Delay", "OK"} default button 2)
	if button_result is "Delay" then
		delay 3600
	end if
end repeat


In this script, no matter what I do it shows a Dialogue window over and over–no matter what button I clilck. I’m not so sure how to get the script to understand “Delay” here.

Secondly, I’m rather clueless as to where to even begin on a countdown for the dialogue window. Again, if no one is around to respond, I don’t want the script on hold forever. It should continue on after something like 10 seconds.
Any help GREATLY appreciated.
Thanks!
Corey

Model: PB G4/867 MHz
Browser: Safari 412
Operating System: Mac OS X (10.4)

OK, so futzing around a bit, I got the dialogue to dismiss or repeat appropriately this way:


repeat
   set button_result to (display dialog "The Backup Script is ready to run. All applications will close and be unavailable for approximately 5 minutes. Click OK to run or DELAY to postpone this operation 1 Hour." buttons {"Delay", "OK"} default button 2)
   if button_result is {button returned:"Delay"} then
       delay 3600
   else
       return
   end if
end repeat

The countdown still eludes me. I’m also not all that sure why putting in a “return” worked? Anyone educate me on this?
THANKS!
Corey

Hi Cory,

I think you are looking for giving up after and exit repeat.

Adding giving up after 10 to the display dialog will mean that the script continues after 10 seconds.

return exits the handler or script it is in, so if you put commands after your second script they would not be executed. exit repeat exits the repeat loop it is contained in, continuing on with the script.

try:

repeat
	set button_result to (display dialog "The Backup Script is ready to run. All applications will close and be unavailable for approximately 5 minutes. Click OK to run or DELAY to postpone this operation 1 Hour." buttons {"Delay", "OK"} default button 2 giving up after 10) -- seconds
	if button_result is {button returned:"Delay"} then
		delay 3600
	else
		exit repeat -- continue with script
	end if
end repeat

Best wishes

John M