Named Styles
As documented previously, Level Styles are defined sets of style attribute values applied to rows based upon the row’s position (level) in the outline hierarchy.
Named Styles are defined sets of style attribute values that are user-assigned to characters, words, sentences, paragraphs, or rows.
Many outline documents created using the provided templates, include sets of named styles by default, such as: Heading and Highlight
Using Omni Automation, you can create and apply named styles in your outline documents.
Instance Properties
The following are the basic properties of the NamedStyle class:
after (NamedStylePosition r/o) • Returns a NamedStylePosition that indicates the slot after this item.
before (NamedStylePosition r/o) • Returns a NamedStylePosition that indicates the slot before this item.
identifier (String r/o) • A unique identifier for the style, which is suitable for long-lived references.
name (String r/o) • The name of the style that is presented in the interface.
Titles of Named Styles | ||
01 | nStyles = document.outline.namedStyles.all | |
02 | titles = nStyles.map(function(nStyle){return nStyle.name}) | |
03 | //-> Heading 1, Heading 2, Heading 3, Heading 4, Heading 5, Heading 6, Highlight 1, Highlight 2, Highlight 3 |
Instance Functions
Here are the instance functions for the NamedStyle class:
remove() --> Boolean • Removes the NamedStyle from the document. Any references to it are disconnected as well.
Delete All Named Styles | ||
01 | document.outline.namedStyles.all.forEach(function(nStyle){ | |
02 | nStyle.remove() | |
03 | }) |
NamedStyle.List
The value of the namedStyles property, NamedStyle.List is the collection of named styles in a document.
Instance Properties
all (Array of Named Styles r/o) • Returns the list of all NamedStyles. Note that the order determine which attribute values are applied if two named styles have conflicting settings.
beginning (NamedStylePosition r/o) • Returns a NamedStylePosition that indicates the position before any existing named styles.
end (NamedStylePosition r/o) • Returns a NamedStylePosition that indicates the position before after existing named styles.
Instance Functions
add(name:String or nil) --> NamedStyle • Makes a new NamedStyle at the end of the NamedStyleList, and optionally assigns it a name.
Create Unique Named Style | ||
01 | newStyleTitle = 'IMPORTANT' | |
02 | nStyles = document.outline.namedStyles.all | |
03 | titles = nStyles.map(function(nStyle){return nStyle.name}) | |
04 | if (titles.indexOf(newStyleTitle) == -1){ | |
05 | nStyle = document.outline.namedStyles.add(newStyleTitle) | |
06 | nStyle.set(Style.Attribute.FontFillColor, Color.red) | |
07 | } else { | |
08 | alertTitle = "NAMING CONFLICT" | |
09 | alertMessage = "A named style title “" + newStyleTitle + "” already exists." | |
10 | new Alert(alertTitle, alertMessage).show(function(result){}) | |
11 | } |
byName(name:String) --> NamedStyle or nil • Returns the first named style that has the specified name, or null if none do.
byIdentifier(identifier:String) --> NamedStyle or nil • Returns the single named style with the specified identifier, or null if no style has that identifier.
And here’s a variation on the previous script that generates a reference to a style instance that is created if it doesn’t already exist. Note that the script uses the byName() instance function to both check for the existence of the style, and to generate a reference to the style instance.
Reference to Named Style | ||
01 | styleTitle = 'iPad Link' | |
02 | if (document.outline.namedStyles.byName(styleTitle) === null){ | |
03 | nStyle = document.outline.namedStyles.add(styleTitle) | |
04 | nStyle.set(Style.Attribute.FontFillColor, Color.blue) | |
05 | url = URL.fromString("https://www.apple.com/ipad") | |
06 | nStyle.set(Style.Attribute.Link, url) | |
07 | } | |
08 | var aStyle = document.outline.namedStyles.byName(styleTitle) |
moveStyles(styles:Array of NamedStyle, position:NamedStylePosition) • Reorders the named styles within the NamedStyleList. This cannot be used to move styles between documents.
duplicateStyles(styles:Array of NamedStyle, position:NamedStylePosition) --> Array of NamedStyle • Returns an array of object references to the new named style duplicates.
Move Named Style to Top | ||
01 | nStyles = document.outline.namedStyles | |
02 | nStyle = nStyles.byName('IMPORTANT') | |
03 | if (nStyle != null){ | |
04 | nStyles.moveStyles([nStyle], nStyles.beginning) | |
05 | } |
Applying Named Styles
The following examples demonstrate how to apply a named style to text objects in an outline document:
Apply Named Style to All Rows | ||
01 | styleTitle = 'Red Text' | |
02 | if (document.outline.namedStyles.byName(styleTitle) === null){ | |
03 | nStyle = document.outline.namedStyles.add(styleTitle) | |
04 | nStyle.set(Style.Attribute.FontFillColor, Color.red) | |
05 | } | |
06 | var aStyle = document.outline.namedStyles.byName(styleTitle) | |
07 | ||
08 | topicColumn = document.outline.outlineColumn | |
09 | rootItem.apply(function(item){ | |
10 | if (item != rootItem){ | |
11 | textObj = item.valueForColumn(topicColumn) | |
12 | textObj.style.setStyle(aStyle) | |
13 | } | |
14 | }) |
And the following script shows how to set the style of all occurrences of a specific word in an outline document. In this case, the word “iPad” is styled with a named style that includes a link to Apple’s iPad webpage.
Apply Named Style to All Occurrences of Word | ||
01 | styleTitle = 'iPad Link' | |
02 | if (document.outline.namedStyles.byName(styleTitle) === null){ | |
03 | nStyle = document.outline.namedStyles.add(styleTitle) | |
04 | nStyle.set(Style.Attribute.FontFillColor, Color.blue) | |
05 | url = URL.fromString("https://www.apple.com/ipad") | |
06 | nStyle.set(Style.Attribute.Link, url) | |
07 | } | |
08 | var aStyle = document.outline.namedStyles.byName(styleTitle) | |
09 | ||
01 | topicColumn = document.outline.outlineColumn | |
02 | rootItem.apply(function(item){ | |
03 | if (item != rootItem){ | |
04 | textObj = item.valueForColumn(topicColumn) | |
05 | wordRanges = textObj.ranges(TextComponent.Words) | |
06 | wordRanges.forEach(function(range){ | |
07 | if(textObj.textInRange(range).string === 'iPad'){ | |
08 | s = textObj.styleForRange(range).get(Style.Attribute.FontSize) | |
09 | aStyle.set(Style.Attribute.FontSize, s) | |
10 | textObj.styleForRange(range).setStyle(aStyle) | |
11 | } | |
12 | }) | |
13 | } | |
14 | }) |
Here is a link to the Add “iPad” Links script saved as an OmniOutliner solitary action:
To install on macOS, download and unpack the ZIP archive, then choose “Plug-Ins…” from the OmniOutliner automation menu, and place the file in the PlugIns folder opened on the desktop. The script will be available from the OmniOutliner Automation menu.
To install on iOS, tap the link, choosing the “Open” option in forthcoming dialog. Then tap “More…” and choose the “Copy to OmniOutliner” option. The installed action will appear in the Plug-Ins view on your device, and will be available from the OmniOutliner automation menu.
This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.