Toggling between collapse all and expand all
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 [I]blnNewState[/I] 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. [CODE]tell application "OmniFocus" global blnNewState try 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 [/CODE] |
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:[LIST=1][*]Editing the boolean values of the two properties at the top will allow you to decide which panel(s) are toggled[*]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.[/LIST] 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 [/CODE] |
[QUOTE=RobTrew;33542]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 [I]blnNewState[/I] below lose their state between runs if the script is run from the OF toolbar.[/QUOTE]
This has been fixed for the next sneaky peek build (which should be posted within half an hour). |
[QUOTE=Ken Case;78852]This has been fixed for the next sneaky peek build (which should be posted within half an hour).[/QUOTE]
Excellent ! Thank you Ken, I really appreciate your putting time into this, an enormously welcome change ... (Can we hope that your work on this will propagate into the toolbar applescript-launching code of OmniOutliner 3 and Omniplan ?) |
[QUOTE=Ken Case;78852]This has been fixed for the next sneaky peek build (which should be posted within half an hour).[/QUOTE]
From Ver 1.8 sneaky peek 77.56.0.133908 onwards the following simplified and marginally faster script will work from the OF toolbar, as well as from the OF script menu. [CODE]-- TOGGLE THE EXPANSION STATE OF TREES IN CONTENT AND/OR SIDEBAR PANELS -- Works if launched from Scripts Menu, a script editor -- or from the OF Toolbar in Ver 1.8 sneaky peek 77.56.0.133908 onwards property pblnToggleContent : true property pblnToggleSidebar : true property pstrContext : "context" global gblnContentExpanded global gblnSidebarExpanded on run tell application id "OFOC" set oWin to front document window of default document -- OPTIONALLY TOGGLE CONTENT EXPANSION if pblnToggleContent then try set blnExpanded to not (gblnContentExpanded) on error set blnExpanded to false end try set refTrees to a reference to trees of content of oWin set expanded of refTrees to blnExpanded set gblnContentExpanded to blnExpanded end if -- OPTIONALLY TOGGLE SIDEBAR EXPANSION if pblnToggleSidebar then try set blnExpanded to not gblnSidebarExpanded on error set blnExpanded to false end try set oSidebar to sidebar of oWin set refLibrary to a reference to tree 2 of oSidebar if selected view mode identifier of oWin is not pstrContext then set refFolders to a reference to (trees of refLibrary where class of value is folder) set expanded of refFolders to blnExpanded else set refContexts to a reference to (trees of refLibrary where (class of value is context)) -- There is an assymetry here (arguably a minor bug ?) -- Childless context trees can have their expanded property set to FALSE by script -- but not to TRUE ... if blnExpanded then set lstTrees to contents of refContexts repeat with oTree in lstTrees try set expanded of oTree to true end try end repeat else set expanded of refContexts to false end if end if set gblnSidebarExpanded to blnExpanded end if end tell end run[/CODE] |
All times are GMT -8. The time now is 10:24 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.