View Single Post
A variant which will hide and restore more complex (mixed) numbering schemes.

Applies to selected rows, or (if none selected) the whole document.

(A little slower - it deals with each row individually).

Code:
-- HIDE AND REVEAL MORE COMPLEX (MIXED) NUMBERING SCHEMES

-- TOGGLE SELECTED (OR ALL) ROWS BETWEEN 
-- NUMBERED AND UN-NUMBERED STATE


-- DEFAULT NUMBERING SETTINGS (ADJUST AS REQUIRED)
property pvarLowerCase : true
property pvarPrefix : ""
property pvarSuffix : "."
property pvarType : "Legal" -- Legal | Letters | Numeric | Roman

property plstOptions : {"Legal", "Letters", "Numeric", "Roman"}
property plstNumbered : {pvarLowerCase, pvarPrefix, pvarSuffix, pvarType}
property pstrType : "heading-type(com.omnigroup.OmniOutliner)"
property pstrHeading : "heading"

on run
	set {dlm, my text item delimiters} to {my text item delimiters, ","}
	tell application id "OOut"
		-- IS THERE A FRONT DOCUMENT ?
		set lstDocs to documents
		if (count of lstDocs) < 1 then return
		set oDoc to first item of lstDocs
		
		-- ARE ANY ROWS SELECTED ?
		set refRows to a reference to selected rows of oDoc
		-- IF NOT, TOGGLE ALL ROWS
		if (count of refRows) < 1 then set refRows to a reference to rows of oDoc
		
		-- IS THE FIRST SELECTED ROW NUMBERED ?
		set oStyle to style of first item of refRows
		set blnNumbered to (value of attribute pstrType of oStyle) is in plstOptions
		
		-- iterate thru the selected lines
		set lstAttribs to name of attributes of oStyle where name begins with pstrHeading
		if blnNumbered then
			-- encode the settings and store in type variable
			-- then clear any prefix, suffix
			repeat with oRow in refRows
				tell style of oRow
					set value of attribute pstrType to (value of attributes where name begins with pstrHeading) as Unicode text
					repeat with i from 2 to 3
						set value of attribute (item i of lstAttribs) to ""
					end repeat
				end tell
			end repeat
		else
			
			repeat with oRow in refRows
				tell style of oRow
					set strValue to value of attribute pstrType
					if strValue ≠ "None" then
						set lstSettings to text items -4 thru -1 of strValue
					else
						set lstSettings to plstNumbered
					end if
					repeat with i from 1 to 4
						set value of attribute (item i of lstAttribs) to item i of lstSettings
					end repeat
				end tell
			end repeat
		end if
	end tell
	set my text item delimiters to dlm
end run