I’m still trying to figure out Applescript, and am not quite there yet (Perl is my toy of choice). I’m trying to write a variant of the example app “Countdown Timer”. My main change is that I want to use user-defaults to manage the default amount of time to put on the counter via a preference panel. I’m really having two problems, one is understanding what the heck the countdown timer thinks its doing with all the data manipulation in the first place, the second is trying to get the string I enter and store for a time “01:45:00” to cast as a date that I can then feed into this bizzarre script.
I enclose the Countdown Timer source for grins:
(* ===== 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
-- Display an alert (as a sheet) asking for the amount of time in the HH:MM:SS format
display dialog "Enter the amount of time for the countdown timer:" default answer "00:00:05" attached to window "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
– Save the current date for display purposes
set currentDate to date (text returned of withReply)
-- Save the start date
set startDate to current date
-- And determine the end date (start date + the countdown timer)
set endDate to startDate + (time of currentDate)
-- Update the contents of the text field
set contents of text field "display" of window "main" to currentDate
-- And let the processing in the idle event handler begin
set countdown to true
end if
end dialog ended
on idle theObject
– See if we are ready to start counting down
if countdown then
– If the required amount of time has elapsed then display our dialog
if (current date) is greater than endDate then
set countdown to false
display alert “Time’s Up!”
else
– Otherwise determine how much time has elapsed (for display purposes)
set elapsedTime to (current date) - startDate
-- Update the display
set contents of text field "display" of window "main" to currentDate - elapsedTime
end if
end if
-- We want to update the idle event every second, so we return 1
return 1
end idle