Add To Dos to iCal from a text file using AppleScript

Feb 20, '07 07:30:04AM

Contributed by: jjgb

I sometimes keep a list of To Dos in text files or Stickies, since I'm not a big user of calendar apps. However, I'm leaving on a trip and needed to sync my To Dos with my cell phone, so I decided to create an AppleScript that reads a text file and converts each line into an iCal To Do item. When running it you just need to specify the text file to read. It will add ToDos to the Home calendar, but that's easy to change. Here's the code:

tell application "iCal"
  set myFile to (choose file with prompt ¬
   "Select a text file to read for To Dos:" of type {"TEXT"})
  open for access myFile
  set myFileContents to read myFile
  close access myFile
  set the paragraph_list to every paragraph of myFileContents
  repeat with i from 1 to the count of paragraphs of myFileContents
    set thisTodo to paragraph i of the myFileContents
    if (thisTodo is not "") then
      set newtodo to (make new todo at end of ¬
       todos of calendar "Home")
      tell newtodo
        set priority to high priority --optional
        set summary to thisTodo
      end tell
    end if
  end repeat
end tell
Please note that I'm a casual AppleScript user, so there might be a better way to do this, but this works for me.

Comments (5)


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