View Single Post
Here is an updated toggle script for expanding and collapsing the outlines in the contents panel and / or the sidebar panel.

This version should work as well from the OF toolbar as from a script menu or any other launch context. (It bypasses the OF Toolbar's unfortunate failure to save the state of global variable between runs, by saving and retrieving its own script object).

You can adjust its behaviour in two ways:
  1. Editing the boolean values of the two properties at the top will allow you to decide which panel(s) are toggled
  2. If both are toggled, you can decide whether they expand in synch or alternation by temporarily uncommenting one line (see note in script), running the script once, and then commenting that line out again.

Note that the very first time you launch it, it may appear to do nothing (the initial script object values may coincide with the current expansion states). Just run it again, and you should find that it toggles expansion with every run.

Useful ? Well, perhaps ... (I happen to use it) but mainly a simple illustration of how to conserve state between runs (despite the quirks of the OF toolbar) and write a toggling script ...

Code:
-- TOGGLE THE EXPANSION STATE OF TREES IN CONTENT AND/OR SIDEBAR PANELS

property pblnToggleContent : true
property pblnToggleSidebar : true

property pstrObjFile : "OFExpandStates"
property pstrSuffix : ".scpt"
property pstrScriptPath : (path to temporary items folder as string) & 
	pstrObjFile & pstrSuffix

-- SCRIPT OBJECT FOR HOLDING DATA BETWEEN RUNS
-- (PATH AS ABOVE)
script sExpandStates
	property pblnContentExpanded : true
	property pblnSidebarExpanded : true
end script

on run
	-- RETRIEVE ANY STORED EXPANSION FLAGS FROM THE LAST USE
	try
		set sExpandStates to load script file pstrScriptPath
	on error
		set pblnContentExpanded to false
		set pblnSidebarExpanded to false
	end try
	
	tell application id "com.omnigroup.omnifocus"
		set oWin to front document window of default document
		
		-- OPTIONALLY TOGGLE CONTENT EXPANSION
		if pblnToggleContent then
			set blnExpanded to not (pblnContentExpanded of my sExpandStates)
			-- UNCOMMENT THE FOLLOWING LINE AND RUN ONCE
			-- TO RESET SYNCH BETWEEN SIDEBAR AND CONTENT EXPANSION
			-- THEN COMMENT AGAIN:
			-- set blnExpanded to true 
			set refTrees to a reference to trees of content of oWin
			set expanded of refTrees to blnExpanded
			set (pblnContentExpanded of my sExpandStates) to blnExpanded
		end if
		
		-- OPTIONALLY TOGGLE SIDEBAR EXPANSION
		if pblnToggleSidebar then
			set blnExpanded to not (pblnSidebarExpanded of my sExpandStates)
			set oSidebar to sidebar of oWin
			set refLibrary to a reference to tree 2 of oSidebar
			set refTrees to a reference to (trees of refLibrary where class of value is folder)
			set expanded of refTrees to blnExpanded
			set (pblnSidebarExpanded of my sExpandStates) to blnExpanded
		end if
	end tell
	store script my sExpandStates in file pstrScriptPath replacing yes
end run

Last edited by RobTrew; 2010-06-15 at 03:58 AM..