View Single Post
Quote:
Originally Posted by curt.clifton View Post
My experience is that changing and restoring the GUI states is more work and substantially slower than using recursion.
Perhaps it depends on how much state you are aiming to conserve.

Just saving and restoring the filter states is simple to do and runs quite fast:

Code:
set lstView to GetView()
set lstProjects to ProjectList("all-projects")
RestoreView(lstView)
lstProjects

on GetView()
	tell application "OmniFocus"
		tell front window
			tell sidebar
				set strSideID to selected smart group identifier
			end tell
			tell content
				set strGroupID to selected grouping identifier
				set strSortID to selected sorting identifier
				set strDurnID to selected task duration filter identifier
				set strFlagID to selected task flagged filter identifier
				set strStateID to selected task state filter identifier
			end tell
		end tell
		{strSideID, strGroupID, strSortID, strDurnID, strFlagID, strStateID}
	end tell
end GetView

on RestoreView(lstView)
	set {strSideID, strGroupID, strSortID, strDurnID, strFlagID, strStateID} to lstView
	tell application "OmniFocus"
		tell front window
			tell sidebar
				set selected smart group identifier to strSideID
			end tell
			tell content
				set selected grouping identifier to strGroupID
				set selected sorting identifier to strSortID
				set selected task duration filter identifier to strDurnID
				set selected task flagged filter identifier to strFlagID
				set selected task state filter identifier to strStateID
			end tell
		end tell
	end tell
end RestoreView

on ProjectList(strFilter)
	tell application id "com.omnigroup.OmniFocus"
		tell front window
			set selected view mode identifier to "project"
			set focus to {}
			tell sidebar
				select library
				set selected smart group identifier to strFilter
			end tell
			set lstProject to {}
			repeat with oTree in trees of content
				set end of lstProject to value of oTree
			end repeat
			-- set focus to lstProject
			lstProject
		end tell
	end tell
end ProjectList