View Single Post
A draft applescript to toggle between collapsing and expanding all project tasks and sub-tasks.

Mainly illustrative - it works if run from the script menu, but its practical utility is limited by the fact that, (at least as of OF build 98016) static variables like blnNewState below lose their state between runs if the script is run from the OF toolbar.

Thus, if used from the toolbar, the script provides only a Collapse All function, whereas if run from the script menu, it alternately functions as Collapse All or Expand All, switching every time it is run.

tell application "OmniFocus"
	global blnNewState
		set blnNewState to not blnNewState
	on error
		set blnNewState to false
	end try
	tell content of window 1
		set oTrees to trees
		repeat with oTree in oTrees
			my Expand(oTree, blnNewState)
		end repeat
	end tell
end tell

on Expand(oTree, blnNewState)
	using terms from application "OmniFocus"
		set oSubTrees to trees of oTree
		if (count of oSubTrees) > 0 then
			set expanded of oTree to blnNewState
			repeat with oSubTree in oSubTrees
				Expand(oSubTree, blnNewState)
			end repeat
		end if
	end using terms from
end Expand

Last edited by RobTrew; 2008-02-27 at 02:30 AM..