So it appears you can't filter by named style

Having a look back through the archives it looks like you can’t filter by a style. Has anything changed over the years that mean it is possible now?

Guess that’s a no.

Just wanted to say that being able to filter by style it will help me a lot, I am using styles as attributes for identifying the type of content of the row, and using them as a filter as well would be great

To the best of my knowledge, you cannot filter by named style. To get a definitive answer though, you should email Omni support.

That said, you can use applescript to hoist —or focus on— lines that match a particular named style (or combination of styles).

I have a named style ‘stricken’ which applies a coloured strikethrough to the text of a given row. This script will hoist every row in the front document that contains this named style. Basically, it builds a list of matching rows and then hoists that list.

tell application "OmniOutliner"
	tell document 1
		
		set hoistList to {}
		repeat with eachRow in rows
			-- set str to id of named style of style of eachRow -- filter by named style's id
			--> {"kIn1bELQDQA"} -- id of named style
			set str to name of named style of style of eachRow -- filter by named style's name
			--> {"stricken"} -- name of named style
			
			if str contains {"stricken"} then 
				set end of hoistList to (get contents of eachRow)
			end if
		end repeat
		
		hoist hoistList -- hoist list of matching rows
	end tell
end tell

It can be modified to match style combinations, or to work only within a given section of a document. It could also be modified to work with the named style id or presumably, any property of a named style. I’ve included the command for that but commented it out.

You could modify it to hoist any unstyled rows and —probably— you could have it get the named style of a selected row and then hoist every row that also has that style. Finally, you could replace the hoist command with select and it should select the same collection of rows. Any command that works with a list of rows could likely be used as a substitute.

A cross-platform variant taking inspiration from Mockman’s approach, using OmniAutomation API. Attempts to hoist rows where some style name matches “Highlight: Yellow”.

(() => {
    "use strict";

    const
        editor = document.editors[0],
        o = document.outline,
        styleName = "Highlight: Yellow",
        items = o.rootItem.descendants.filter(
            x => x.style.namedStyles.some(
                y => y.name === styleName
            )
        );
    return (
        editor.focusedItems = items,
        items
    )
})();
3 Likes