The Omni Group Forums

The Omni Group Forums (
-   OmniFocus Extras (
-   -   Using ScriptingBridge to iterate tasks in the right pane (

ksenia 2008-06-21 07:21 PM

Using ScriptingBridge to iterate tasks in the right pane

I want to export data from the right pane in OF, using shell scripting and Python.

So far I have:

#!/usr/bin/env python
from ScriptingBridge import *

def process_tree(tree):
for el in tree.trees():

of = SBApplication.applicationWithBundleIdentifier_("com.omnigroup.OmniFocus")
doc = of.defaultDocument()
tree = doc.documentWindows()[0].content()

But I can't find a way to get the actual task from a tree element. does work, but other properties (deadline, note) doesn't.

What is the correct syntax?

Thanks for any help

ksenia 2008-06-22 01:44 PM

I couldn't solve it, so I changed the strategy - instead of the selection in the right pane, I am querying all tasks in OF through contexts. It works this way. This is first time I use ScriptingBridge, so I probably shouldn't get too excited... but man, this is really cool - adding functionality to your favorite app using your favorite programming language... :-)

In case anyone interested, my script tries to "visualize" time data from OF. The part I miss the most in GTD in general and in OF in particular is the ability to query my trusted system and withing 5 minutes answer the question "When can I expect it to be ready?"
So the script does the following:

- Loop through all tasks in OF and filter only those with due dates (or with parent that has due date)
- Create iCalendar vevent entry from every task, calculate start and end according to the deadline, duration of the task AND duration of other tasks (you can only do one thing at a time)
- Schedule those events ONLY during working hours (according to iCal setting)
That means that if I have two tasks, both 8 hours long, both with deadline on friday 9:00, one will be scheduled on wednesday, and one on thursday.
To make the updates more easy, the script serves generated iCalendar data on the fly through local Python http server. So I've subscribed to this local server (e.g. [url]http://localhost:8888[/url]) in iCal, and now the calendar is auto-magically updated every 5 minutes with fresh data from OF.

I am only using it few hours now, but even at this point seeing my tasks automatically appear as scheduled blocks in iCal is awesome. A lot needs to be done, but when it's ready I'll package the script and release it, to share the joy :)

iNik 2008-06-24 08:36 AM

[QUOTE]But I can't find a way to get the actual task from a tree element. does work, but other properties (deadline, note) doesn't.[/QUOTE]

Trees are sort of XML constructs and are not identical to the task/project/context they represent.

What you're looking for is the "value" property of the tree element you're looking at. That will be a reference to the actual object.

No idea how to implement this in Python, but it should send you in the right direction.

Also, tree scripting is substantially faster for just iterating through a list than recursing by context, project, or whatnot.

All times are GMT -8. The time now is 07:32 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.