The Omni Group Forums

The Omni Group Forums (
-   OmniFocus Extras (
-   -   A blind patch in OmniFocus Applescript library (

RobTrew 2010-06-09 01:09 PM

A blind patch in OmniFocus Applescript library
(Generalised recursion through projects and tasks selected in the contents panel would be simpler and quicker if ITEM objects - the values of tree nodes representing the parents of groupings in Contexts view (and the Inbox icon) - had a [B]tasks[/B] property)

Recursive walks through the objects selected in the content panel are frequently needed by useful OmniFocus applescripts.

Doing this is a little slowed and complicated by a kind of of cyclops or 'blind patch' in the OF applescript library - the single property 'item' objects which lie behind the labelled parents of groupings in Context view, and the Inbox icon in Project view, and which provide no access to the task lists of which they are parents.

Recursion through the data selected in the contents panel can be done either:[LIST][*]through the generic Trees objects (simpler but slower),[*]or through the specific objects (projects, contexts, tasks and subtasks etc) which are accessible through the [I]value[/I] property of each tree node.[/LIST]This latter approach can be noticeably faster, and can be started by immediately retrieving a list of the underlying objects (values) of the selected tree nodes, and starting work on them.

[CODE]tell application "OmniFocus"
set oDoc to default document
tell content of front window
[B]set refTrees to a reference to selected trees[/B]

-- get a list of the objects associated with the tree nodes
[B]set lstValues to value of refTrees[/B]

-- If this gives a list of projects, contexts, or tasks,
-- faster recursion through the object model can begin,

-- but if it returns "items"
-- (e.g. grouping dividers in a context view)
-- these items lack a "tasks" property through which exploration
-- of the data can begin
end tell
end tell[/CODE]

This works well if the objects are projects, contexts, or tasks.
This route to recursion gets blocked, however, if the objects are of the 'item' class (context group parents etc).
Despite being parents of task lists, these recalcitrant and cyclopic objects have only one property (their own class type), and give no access to the task lists of which they are parents ...

You can select objects in the content panel, and compare the relative richness of their tree nodes and underlying objects, by running the following script:


tell application "OmniFocus"
set oDoc to default document
tell content of front window
set lstTree to selected trees
if length of lstTree > 0 then
set oTree to first item of lstTree
set lstTreeProps to properties of oTree as list
set strTreeclass to class of oTree as string

set oValue to value of oTree
set strObjectClass to class of oValue as string

set lstObjectProps to properties of oValue as list

my PropertyReport({strTreeclass, lstTreeProps}, {strObjectClass, lstObjectProps})
display dialog "Select an element in the contents panel," &
return & "and run the script again"
end if
end tell
end tell

on PropertyReport({strTreeclass, lstTreeProps}, {strObjectClass, lstObjectProps})
set lngTreeCount to count of lstTreeProps
set lngObjCount to count of lstObjectProps

set strTreeMsg to ""
set strObjMsg to ""

if lngObjCount > 1 then
set strObjMsg to "Selected *" & strObjectClass & "* has " &
(lngObjCount as string) & " properties"
set oProp to first item of lstObjectProps
set strObjMsg to ("The only property of the selected *" & strObjectClass &
"* is the type of its class:" & quote & oProp as string) & quote
& return & return & "(no access to subtasks through this *" & strObjectClass & "* object)"
end if

set strTreeMsg to ("Selected *" & strTreeclass & "* has " &
lngTreeCount as string) & " properties"

display dialog strTreeMsg & return & return & strObjMsg
with title "Properties of content tree node and underlying object"
end PropertyReport

In short, this is a request for the addition of a [B]tasks[/B] property to the item objects :-)

I have filed a request under Help > Send Feedback in OF


All times are GMT -8. The time now is 11:25 AM.

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