Re: How do I schedule a script
Re: How do I schedule a script
- Subject: Re: How do I schedule a script
- From: Geoff Graham <email@hidden>
- Date: Thu, 15 Jan 2004 09:38:04 -0500
Gooday,
Just for academic purposes, I thought I'd post an applescript for
scheduling things. No doubt cron is better, but this works also. It
calls the DoMyThing handler about 12:30 AM everyday. I like it because
it is easy to return numeric date strings for daily file saves,
reports, etc. BTW, you have to save it as a stay open application. The
date and time slug handlers are straight from the os 9 applescript
guidebooks, which I can't find anymore on apple's website. On X, you
can't install them anyway, but you can dig through them and find the
example scripts...
geoff
begin script:
property Gotime : 0
property lastday : 20030915
set lastday to (format_date_using((current date), "", {"YYYY", "MM",
"DD"}))
tell application "Finder" to activate
on idle
set isit to format_time_using(the current date, "", {"H", "MM"})
set yesitis to (format_date_using((current date), "", {"YYYY", "MM",
"DD"}))
if isit is greater than Gotime then
if yesitis is greater than lastday then
DoMyThing()
set lastday to yesitis
return 64800
--doesn't start checking the time again until evening
end if
end if
return 1800
-- checks every 30 minutes if it is tomorrow yet
end idle
on DoMyThing()
--your thing goes here
end DoMyThing
on format_date_using(this_date_record, delimiter_string, format_list)
-- get the numeric day
set numeric_day to the day of this_date_record
-- get the month
set month_name to the month of this_date_record
-- convert month to number
set the list_of_months to {January, February, March, April ,
, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if item i of the list_of_months is the month_name then
set the numeric_month to i
exit repeat
end if
end repeat
-- get the numeric year as text
set numeric_year to the year of this_date_record as string
set the formatted_date to ""
-- count the number of items in the list
set the item_count to the count of the format_list
-- parse the format list
repeat with i from 1 to the item_count
set this_item to item i of the format_list
if this_item is "D" then
set the formatted_date to ,
the formatted_date & numeric_day as string
else if this_item is "DD" then
if the numeric_day is less than 10 then ,
set numeric_day to ,
("0" & (the numeric_day as string))
set the formatted_date to ,
the formatted_date & numeric_day as string
else if this_item is "M" then
set the formatted_date to ,
the formatted_date & numeric_month as string
else if this_item is "MM" then
if the numeric_month is less than 10 then ,
set numeric_month to ,
("0" & (the numeric_month as string))
set the formatted_date to ,
the formatted_date & numeric_month as string
else if this_item is "YY" then
set the formatted_date to ,
the formatted_date & ,
((characters 3 thru 4 of numeric_year) as string)
else if this_item is "YYYY" then
set the formatted_date to ,
the formatted_date & numeric_year
end if
if i is not the item_count then
-- add delimiter
set the formatted_date to ,
the formatted_date & delimiter_string as string
end if
end repeat
return the formatted_date
end format_date_using
on format_time_using(this_date_record, delimiter_string, format_list)
set the time_index to the time of this_date_record
set the hour_index to ((the time_index) / hours) div 1
set the minute_index to ,
(((the time_index) / minutes) - (the hour_index * 60)) div 1
set the seconds_index to ,
((the time_index) - (the hour_index * 3600) - (the minute_index *
60)) div 1
set the formatted_time to ""
-- count the number of items in the list
set the item_count to the count of the format_list
-- parse the format list
repeat with i from 1 to the item_count
set this_item to item i of the format_list
if this_item is "H" then
set the formatted_time to ,
the formatted_time & the hour_index as string
else if this_item is "HH" then
if the hour_index is less than 10 then ,
set hour_index to ,
("0" & (the hour_index as string))
set the formatted_time to ,
the formatted_time & hour_index as string
else if this_item is "M" then
set the formatted_time to ,
the formatted_time & the minute_index as string
else if this_item is "MM" then
if the minute_index is less than 10 then ,
set minute_index to ,
("0" & (the minute_index as string))
set the formatted_time to ,
the formatted_time & minute_index as string
else if this_item is "S" then
set the formatted_time to ,
the formated_time & the seconds_index as string
else if this_item is "SS" then
if the seconds_index is less than 10 then ,
set seconds_index to ,
("0" & (the seconds_index as string))
set the formatted_time to ,
the formatted_time & seconds_index as string
end if
if i is not the item_count then
-- add delimiter
set the formatted_time to ,
the formatted_time & delimiter_string as string
end if
end repeat
return the formatted_time
end format_time_using
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.