Dialog with countdown timer

I would like to create a dialog that times out after so many seconds, but displays how many seconds are left. It is easy to make it timeout as I have shown in my current script below. What I would like is a timer like when you tell your machine to shut down and it says “If you do nothing, the system will restart in XX seconds”.

This http://macscripter.net/viewtopic.php?id=11957 script almost does the job, but it’s rather clunky.

Does anyone have a better idea?

Thanks,
Jeremy


set D to display dialog "Should I do a backup?" buttons {"Yes", "No"} default button ¬
    "Yes" with icon caution giving up after 60
if (button returned of D) is "Yes" or (gave up of D) then
    say "I'm gonna run"
else
    say "I'm not gonna run"
end if

Hi,

the smartest solution is an AppleScript Studio application,
in plain AppleScript you can do only this


repeat with i from 60 to 1 by -1
	set D to display dialog "Should I do a backup?" & return & i & " seconds left" buttons {"Yes", "No"} default button ¬
		"Yes" with icon caution giving up after 1
	if (button returned of D) is "Yes" then
		say "I'm gonna run"
		exit repeat
	else if i = 1 or (button returned of D) is "No" then
		say "I'm not gonna run"
		exit repeat
	end if
end repeat

Thanks for the reply. I’m a newbie when it comes to AppleScript.

As was probably obvious, the script I posted above is just a part of the whole script I have created. I don’t mind an AppleScript Studio application if it will work for what I need to do. Where can I find out how to do a minimal example? Is it different from plain AppleScript?

Thanks again,
Jeremy

Yes, it is quite different from plain AppleScript

AppleScript Studio is a full programming environment with capabilities to use custom windows, text fields and many other UI elements.

Here you can find a tutorial for a minimal example