View Single Post
Quote:
Originally Posted by malisa View Post
I just re-implemented folders, or actually a more AofF folder structure ... but knowing that I can 'flatten' things with a couple clicks will be nice too.
This version of the script behaves as a toggle - the first click gives a flat view, a second click returns to folder view.

Code:
-- Toggle between a flat and a folder-indented sidebar
-- (An experiment in conditional compilation, as latest Sneaky Peaks 
-- offer quicker (and more rationally ordered) 
-- flattening of the project list)

property pstrNewScript : "
script
on GetProjects(oDoc)
	using terms from application \"OmniFocus\"
		return flattened projects of oDoc
	end using terms from
end GetProjects
end script
"

property pstrOldScript : "
script
on GetProjects(oParent)
	using terms from application \"OmniFocus\"
		tell oParent
			-- ADJUST THE WHERE QUERIES TO MATCH THE PURPOSE
			set lstProjects to projects
			set lstFolders to folders
		end tell
		repeat with oFolder in lstFolders
			set lstProjects to lstProjects & my GetProjects(oFolder)
		end repeat
		return lstProjects
	end using terms from
end GetProjects
end script
"

tell application id "com.omnigroup.OmniFocus"
	set oDoc to default document
	set oWin to front document window of oDoc
	
	if my IsNarrowed(focus of oWin) then
		set focus of oWin to {}
	else
		if build number ≥ "77.57.0.134152" then
			set oScript to run script pstrNewScript
		else
			set oScript to run script pstrOldScript
		end if
		set lstProjects to GetProjects(oDoc) of oScript
		set focus of oWin to lstProjects
	end if
end tell

-- Detect whether the sidebar has a narrowed focus
on IsNarrowed(oFocus)
	repeat with oObj in oFocus
		return true
	end repeat
	return false
end IsNarrowed

Last edited by RobTrew; 2010-06-22 at 10:23 PM..