Programmish
Python and iCal — ToDo List

Digging around i PyObjC and the CalendarStore (which is the local shared calendar database for which ever user is logged in), I thought it would be fun to pull the Tasks from my ToDo list into Python. This small chunk of code will extract all available of your tasks from all of your calendars:

#!/usr/bin/python
from CalendarStore import CalCalendarStore

store = CalCalendarStore.defaultCalendarStore()
calendars = CalCalendarStore.calendars(store)
predicate = CalCalendarStore.taskPredicateWithCalendars_(calendars)
tasks = store.tasksWithPredicate_(predicate)

for task in tasks:
    completedMark = " "
    completeDate = task.completedDate()
    if completeDate is not None:
        completedMark = "#"
    print "%s(%s:%s) %s" % (completedMark, task.calendar().title(), task.priority(), task.title())
    print "   uid: %s" % (task.uid())

The end result is a list of tasks:

#(Home:5) Look, a task!
   uid: 1AD57B3A-C31A-4BBD-BCB7-19E78E4060B9
 (Home:1) Task #1
   uid: 240C7449-B74B-4666-98DF-1A6C6F6564CF
 (Work:5) Task #2
   uid: A36AFE1B-5BC6-4A3A-B18F-7B5DB4E4A5F3
 (Home:9) Task #3
   uid: A771147B-3F98-4895-8CB1-8466A7433DD0

The values in parentheses are the Calendar from which the task is taken, and the task priority. Tasks without a priority have a value of 0, priority of High is 1, Medium is 5, and Low is 9. The text following the parenthesized values is the title of the task, below which is the Task’s UID, which is used by the CalendarStore to reference specific tasks. Any tasks that have a completedDate of None are not yet marked as complete in iCal. Those tasks that are complete are printed with a hash (#) sign in front of them.

One Response to Python and iCal — ToDo List
You can leave a response, or trackback from your own site.
  1. [...] Python and iCal — ToDo List Apr [...]

Leave a Reply