08.10.07

iCal countdown

Posted in AppleScript, Macintosh at 10:48 am by Lazra

I wrote an other little AppleScript for someone. It creates events in iCal as a countdown. First, you can choose one of your calendars. Then enter the start- and enddate. It will count down and say every day “x days left”. I tested it with my local date format, but it is supposed to work anywhere since the Mac knows his date format.

on run

tell application “iCal”

set cal_list to {}

repeat with x from number of calendars to 1 by -1
set the beginning of cal_list to name of calendar x
end repeat

set cal_list_string to “”
repeat with x from 1 to number of calendars
set cal_list_string to cal_list_string & (x as text) & ” – ” & item x of cal_list & return
end repeat

end tell

display dialog cal_list_string default answer “”
set cal_number to text returned of result as number

display dialog “start date” default answer “”
set anfangsdatum to date (text returned of result)

display dialog “end date” default answer “”
set enddatum to date (text returned of result)

repeat with anzahl_tage from 1 to 99999
if anfangsdatum + (anzahl_tage * 3600 * 24) is enddatum then
exit repeat
end if
end repeat

tell application “iCal”

tell calendar cal_number

set x_date to anfangsdatum

repeat with x from anzahl_tage to 0 by -1
set x_date to x_date + (3600 * 24)
set event_summary to “x & ” days left”
if x is not 1 then
set event_summary to “x & ” days left”
else
set event_summary to “one day left”
end if
make new event at the beginning with properties {summary:event_summary, start date:x_date, end date:x_date}
end repeat

end tell

end tell

end run

3 Comments »

  1. Terry said,

    I tried this script and it leaves a bunch of X’s on each day. I also had to fiddle with the quotes between X and days left” to get it to compile.
    Any ideas?
    Should it be
    “x” & ” days left”
    ?

    Also the quotes seem corrupted. I had to fix them. Must be HTML

  2. Matt said,

    I am having trouble getting this to work…but this is probably due to my totally unfamiliarity with applescript. Can I copy and paste….if so, where do I need to insert my data.

    Thanks for any help, if this works for me it would be a huge help.

  3. Bob said,

    it doesnt work for the above people because wordpress fudges up the quotes, just do a search and replace in your favourite text editor.


Leave a Comment