The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

A blind patch in OmniFocus Applescript library Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
(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 tasks 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:
  • through the generic Trees objects (simpler but slower),
  • or through the specific objects (projects, contexts, tasks and subtasks etc) which are accessible through the value property of each tree node.
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.

tell application "OmniFocus"
	set oDoc to default document
	tell content of front window
		set refTrees to a reference to selected trees
		-- get a list of the objects associated with the tree nodes
		set lstValues to value of refTrees
		-- 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
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 tasks property to the item objects :-)

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


Last edited by RobTrew; 2010-06-10 at 11:51 PM.. Reason: amended code to show class of 'value' of tree node

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python OmniFocus library for generating reports psidnell OmniFocus Extras 14 2013-04-11 11:54 PM
GTD: OmniFocus as Reference Library vvlevchenko Applying OmniFocus 14 2012-04-24 06:12 PM
Skew - am I blind? jem OmniGraffle General 0 2010-05-03 12:24 AM
Fixing the blind patch in "Contexts View" RobTrew OmniFocus 1 for Mac 3 2007-08-21 08:22 AM

All times are GMT -8. The time now is 08:28 PM.

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