Enable T610 phones to show all-day iCal events

Sep 23, '03 09:25:00AM

Contributed by: Anonymous

We all (well, most of us, I think) are of the opinion that the iCal - iSync - mobile phone syncing is a great addition. Well, I found out that sadly enough, all-day events where not correctly synchronized to my T610; they are just left out. This renders the organiser in the T610 pretty useless.

So I created an AppleScript which automatically creates a series of normal events from 1 to 4 am out of an all-day event which can span several days. These events are all put in a separate calendar, which can be turned off in iCal, but is nevertheless then synced to the phone, showing all the dates. It is pretty complicated because AppleScript actually does not give you any information on the end date of an all-day-event; I had to get that information directly from the .ics file. Therefore, your calendar name should not have any spaces in it, or just the first day of the recurring event will be parsed.

There's a note on VersionTracker's iSync page discussing this issue, and it includes an email address where you can send feedback requesting better support for all-day events.

Read the rest of the hint for the script...

[robg adds: I have checked that the script syntax checks properly in AppleScript, but I have not tested it.]

property AlldayCalendarName : "All-Day Events"
property monthlist : ¬
  {January, February, March, April, May, June, July, August, September, October, November, December}
property theweeks : 4

tell application "iCal"
  
  --find the Allday Events calendar
  set theNum to 0
  set Calendartitles to {}
  repeat with i from 1 to count of calendars
    if title of item i of calendars is AlldayCalendarName then set theNum to 1
    copy title of item i of calendars to end of Calendartitles
  end repeat
  
  if theNum is 0 then
    --create the calendar and rescan the calendar titles
    create calendar with name AlldayCalendarName
  end if
  
  --identify the AlldayCalendar
  set i to 1
  repeat with theItem in calendars
    if the title of the item i of calendars is equal to AlldayCalendarName then
      set theNum to i
      exit repeat
    end if
    set i to i + 1
  end repeat
  set AlldayCalendar to item theNum of calendars
  --delete all old events in here
  delete every event in AlldayCalendar
  
  --now scan every calendar for all-day events and make an identical copy
  --in the AlldayCalendar, only as normal event from 1:00 to 4:00 am
  repeat with theCal in calendars
    
    if title of theCal is not AlldayCalendarName then
      repeat with theEvent in events of theCal
        --only look x weeks back
        if theEvent is allday event and the (start date of theEvent) >  ¬
        ((current date) - (theweeks * weeks)) then
          set theSummary to summary of theEvent
          set theuid to the uid of theEvent
          set thestartdate to the start date of theEvent
          try
            set theendstring to do shell script "cat ~/Library/Calendars/" &  ¬
            title of theCal & ".ics | grep -iA 6 " & theuid & " | grep DTEND"
          on error
            set theendstring to ""
          end try
          if theendstring = "" then
            set theenddate to thestartdate
          else
            set theenddate to current date
            set time of theenddate to 0
            set year of theenddate to text 18 thru 21 of theendstring as integer
            set monthnumber to text 22 thru 23 of theendstring as integer
            set month of theenddate to item monthnumber in monthlist
            set day of theenddate to text 24 thru 25 of theendstring as integer
            set theenddate to theenddate - days
          end if
          --the next is the enddate of the ical record
          set theendtime to thestartdate
          --set the time from 1 to 4 in the morning
          set the time of thestartdate to 60 * 60 * 1
          set the time of theendtime to 60 * 60 * 4
          --set the time of the last date to 5 to avoid an early stop of the repeat loop
          set the time of theenddate to 60 * 60 * 5
          --repeat adding an event for all the days
          repeat until thestartdate > theenddate
            make new event at end of events of AlldayCalendar ¬
              with properties {start date:thestartdate, summary:theSummary, end date:theendtime}
            set thestartdate to thestartdate + days
            set theendtime to theendtime + days
          end repeat
        end if
      end repeat
    end if
  end repeat
end tell
Improvements welcomed!

Comments (12)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030918141857407