Re: Time
Re: Time
- Subject: Re: Time
- From: David Simerly <email@hidden>
- Date: Thu, 27 Sep 2001 13:51:45 -0700
- Url: http://www.digital-native.com
on 9/27/01 4:54 AM, david atyahoo at email@hidden wrote:
>
If I want something to happen at a specific time e.g. 9:30pm what would the
>
code be.
Here's what I use:
----- begin script
property delay_secs : 24 * 60 * 60 -- 24 hours
property script_path : (((path to scripts folder) as text) & "Test Action")
property time_constant : "9:30 am"
property trigger_time : ""
on idle
if (current date) trigger_time then
try
set timed_script to (load script alias script_path)
tell timed_script to doSomething()
resetTrigger()
on error err_mess number err_no
beep
display dialog "Error #" & err_no & ": " & err_mess
end try
end if
return 30 -- seconds until next idle
end idle
on run
resetTrigger()
end run
on resetTrigger()
if time_constant is not "" then
set trigger_time to date time_constant of ((current date) +
delay_secs)
else
set trigger_time to ((current date) + delay_secs)
end
end resetTrigger
------ end script
Tweak delay_secs and time_constant to change when the action triggers. Set
time_constant to "" to have it not locked into a specific time. And while
we're on the subject of time, here's some time-related snippets you might
find useful:
----- begin example
set today to current date
set time of today to 0 -- midnight
set time of today to (12 * 60 * 60) -- noon
set yesterday to (today - (24 * 60 * 60))
set cur_day to weekday of today
set day_num to day of today
set days_in_month to daysInMonth(month of today)
set a_month_ago to (today - (days_in_month * (24 * 60 * 60)))
on daysInMonth(the_mo)
set targ_date to current date
set time of targ_date to 0
set month of targ_date to the_mo
set num_days to 27
repeat until month of targ_date the_mo
set num_days to num_days + 1
set day of targ_date to num_days
end repeat
return num_days - 1
end daysInMonth
----- end example
HTH.
DS
______________________________________
Digital Native
Your guide through the virtual jungle.
______________________________________
"You may fool all the people some of the time, you can even fool some of the
people all of the time, but you cannot fool all of the people all the time."
-- Abraham Lincoln
- Follow-Ups:
- Re: Time
- From: John W Baxter <email@hidden>