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 Today's Posts

 
Detecting childless projects and tasks in Applescript Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
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..
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
repeating projects/tasks when all tasks/subtasks are complete? djc225 OmniFocus 1 for Mac 1 2012-03-20 06:55 PM
Applescript Framework to Loop Through Projects and Tasks elrjax OmniFocus Extras 2 2012-01-23 11:04 PM
Applescript for dependent projects fudster OmniFocus Extras 10 2011-03-17 03:00 PM
AppleScript for deleting completed tasks and projects snarke OmniFocus Extras 8 2009-01-20 02:22 PM
Q: Tasks (or projects) waiting on other tasks? budney Applying OmniFocus 10 2008-12-30 04:42 AM


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


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