i’m trying to modify the example countdown so where you specify an end date and it gives you the time remaining, but so far it doesn’t work at all. any ideas?
( Coundown Timer.applescript )
( ===== Properties ===== )
property countdown : false
property currentDate : 0
property startDate : 0
property endDate : 0
( ===== Event Handlers ===== )
on launched theObject
– Show the window
set visible of window “main” to true
--[i][color=olive] Display an alert (as a sheet) asking for the amount of time in the HH:MM:SS format[/color][/i]
[color=blue]display dialog[/color] "Enter the date to countdown to:" [color=blue]default answer[/color] "8:00 PM" [color=blue]attached to[/color] [color=blue]window[/color] "main"
end launched
on dialog ended theObject with reply withReply
– See if the “OK” button has been clicked
if button returned of withReply is “OK” then
[b][color=blue]set[/color][/b] [color=green]endDate[/color] [b][color=blue]to[/color][/b] [color=blue]date[/color] ([color=blue]text returned[/color] [b][color=blue]of[/color][/b] [color=green]withReply[/color])
--[i][color=olive]display dialog endDate as text[/color][/i]
[b][color=blue]set[/color][/b] [color=blue]contents[/color] [b][color=blue]of[/color][/b] [color=blue]text field[/color] "end date" [b][color=blue]of[/color][/b] [color=blue]window[/color] "main" [b][color=blue]to[/color][/b] [color=green]endDate[/color]
[b][color=blue]set[/color][/b] [color=green]startDate[/color] [b][color=blue]to[/color][/b] [color=blue]current date[/color]
[b][color=blue]set[/color][/b] [color=green]currentDate[/color] [b][color=blue]to[/color][/b] [color=blue]current date[/color]
--[i][color=olive] set contents of text field "display" of window "main" to currentDate[/color][/i]
[b][color=blue]set[/color][/b] [color=green]countdown[/color] [b][color=blue]to[/color][/b] [color=blue]true[/color]
[b][color=blue]end[/color][/b] [b][color=blue]if[/color][/b]
end dialog ended
on idle theObject
if countdown then
if (current date ) is greater than endDate then
set countdown to false
display alert “We’re here!” attached to window “main”
else
set timeRemaining to (endDate as date ) - (current date ) as date
–display dialog ((current date) as text) & return & endDate & return & timeRemaining
– Update the display
[b][color=blue]set[/color][/b] [color=blue]contents[/color] [b][color=blue]of[/color][/b] [color=blue]text field[/color] "display" [b][color=blue]of[/color][/b] [color=blue]window[/color] "main" [b][color=blue]to[/color][/b] [color=green]timeRemaining[/color]
[b][color=blue]end[/color][/b] [b][color=blue]if[/color][/b]
[b][color=blue]end[/color][/b] [b][color=blue]if[/color][/b]
--[i][color=olive] We want to update the idle event every second, so we return 1[/color][/i]
[b][color=blue]return[/color][/b] 1
end idle
jonn8
May 11, 2004, 12:32am
#3
You can take a look at a demo project I posted last year:
http://homepage.mac.com/jonn8/as/dist/Countdown.hqx
Jon