View Single Post
Using where / whose clauses is generally quite a lot faster (and simpler to write) in Applescript than iterating with repeat loops and applying tests.

For efficient recursive walks through nested outlines, one really wants to be able to distinguish, within a where statement, between those nodes which have children and those which are childless leaves.

This is not as easy in OmniFocus as it is in OmniOutliner, in which the Applescript library provides the useful has subtopics property.

Has anyone found an elegant or efficient idiom for doing something similar in OmniFocus ?

A rather clumsy, and rather inefficient-looking idiom which does at least work is:

Code:
where (container of (tasks of tasks) is tasks)
which filters for childless (taskless) projects or tasks, so a rather unreadable equivalent of has subtopics is

Code:
where not (container of (tasks of tasks) is tasks)
To see a list of projects which have no tasks, for example, you could write:

Code:
tell application "OmniFocus"
	set oDoc to default document
	set lstChildless to my ChildlessProjects(oDoc)
	set focus of front document window of oDoc to lstChildless
end tell

on ChildlessProjects(oParent)
	using terms from application "OmniFocus"
		tell oParent
			set lstProjects to projects where (container of (tasks of tasks) is tasks) and ((status is active) or (singleton action holder is true))
			set lstFolders to folders where hidden is false
		end tell
		repeat with oFolder in lstFolders
			set lstProjects to lstProjects & my ChildlessProjects(oFolder)
		end repeat
		return lstProjects
	end using terms from
end ChildlessProjects
But I suspect that something more efficient and legible should be possible ...

Any thoughts ?

--

Last edited by RobTrew; 2010-06-20 at 03:13 PM..