View Single Post
The sample scripts on the OmniOutliner Extras page include:
  • Collapse to Level of Selected Item,
  • and Collapse to Level X
These are fine, but my flow of thought is sometimes disrupted unnecessarily by having to select a target item, or (particularly for expanding) calculate and specify a target level.

It is easier for me to simply:
  • Expand a little,
  • Collapse a little.
(perhaps repeating one of these simple gestures to fine-tune).

This is the pair of scripts which I use:

Expand one level more:
Code:
property plstLevel : {}

AdjustExpansion(1)
set plstLevel to {}

on AdjustExpansion(lngDelta)
	tell application id "com.omnigroup.OmniOutlinerPro3"
		if (count of documents) < 1 then return
		set oDoc to front document
		set lngNewMax to (my DeepestLevel(oDoc, true)) + lngDelta
		tell oDoc
			set expanded of (rows where level ≤ lngNewMax) to true
			set expanded of (rows where level > lngNewMax) to false
		end tell
	end tell
end AdjustExpansion

on DeepestLevel(oDoc, blnExpandedOnly)
	set lngMax to 0
	using terms from application "OmniOutliner Professional"
		if blnExpandedOnly then
			set plstLevel to level of rows of oDoc where expanded is true
		else
			set plstLevel to level of rows of oDoc
		end if
		repeat with iLevel from 1 to length of plstLevel
			set lngLevel to item iLevel of plstLevel
			if lngLevel > lngMax then set lngMax to lngLevel
		end repeat
	end using terms from
	lngMax as integer
end DeepestLevel
Collapse one level more:
Code:
property plstLevel : {}

AdjustExpansion(-1)
set plstLevel to {}

on AdjustExpansion(lngDelta)
	tell application id "com.omnigroup.OmniOutlinerPro3"
		if (count of documents) < 1 then return
		set oDoc to front document
		set lngNewMax to (my DeepestLevel(oDoc, true)) + lngDelta
		tell oDoc
			set expanded of (rows where level ≤ lngNewMax) to true
			set expanded of (rows where level > lngNewMax) to false
		end tell
	end tell
end AdjustExpansion

on DeepestLevel(oDoc, blnExpandedOnly)
	set lngMax to 0
	using terms from application "OmniOutliner Professional"
		if blnExpandedOnly then
			set plstLevel to level of rows of oDoc where expanded is true
		else
			set plstLevel to level of rows of oDoc
		end if
		repeat with iLevel from 1 to length of plstLevel
			set lngLevel to item iLevel of plstLevel
			if lngLevel > lngMax then set lngMax to lngLevel
		end repeat
	end using terms from
	lngMax as integer
end DeepestLevel

Last edited by RobTrew; 2010-11-04 at 11:50 PM.. Reason: Tidied the code a little