Export iCal To Do items to OmniOutliner

From Mac OS X Hints - macosxhints.com. This script is UNTESTED - iCal doesn’t allow for printing a simple list of To Dos as an outline (with no calendar info). This Applescript will export To Dos into a new outline in OmniOutliner. Each calendar has any associated To Dos indented beneath it.

Optimaly, the complied script should be in ~/Library → Scripts → Applications → iCal → Export iCal todos to OO.scpt, so that it appears in the script menu only when iCal is frontmost…

OS version: OS X

set theCals to {}
set theTodos to {}

tell application "OmniOutliner"
  activate
  set doc_ID to make new document
  --set doc_ID to document 1
  set isStatusVisible of doc_ID to false
  set topic of row 1 of doc_ID to "Master todo list"
    
  tell application "iCal"
    set theCals to calendars
    set i to 1
    repeat with a_Cal in theCals
      set calTitle to title of calendar i
      my newRow(doc_ID, calTitle, false)
      repeat with aTD in todos of a_Cal
        set TD_name to summary of aTD
        my newRow(doc_ID, TD_name, true)
      end repeat
    set i to i + 1
    end repeat
  end tell
end tell

on newRow(doc_ID, txt, flIndent)
  tell application "OmniOutliner"
    set z to make with properties {topic:txt} new row at end of doc_ID
    indent z
    if flIndent then
      -- there's some sort of bug that doesn't allow
      -- indenting z twice in a row
      set z to last row of doc_ID
      indent z
    end if
  end tell
end newRow