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:

nStyles = document.outline.namedStyles.all titles = nStyles.map(function(nStyle){return nStyle.name})

Instance Functions

Here are the instance functions for the NamedStyle class:

document.outline.namedStyles.all.forEach(function(nStyle){nStyle.remove()})
omnioutliner:///omnijs-run?script=document%2Eoutline%2EnamedStyles%2Eall%2EforEach%28function%28nStyle%29%7BnStyle%2Eremove%28%29%7D%29

NamedStyle.List

The value of the namedStyles property, NamedStyle.List is the collection of named styles in a document.

Instance Properties

Instance Functions

newStyleTitle = 'IMPORTANT' nStyles = document.outline.namedStyles.all titles = nStyles.map(function(nStyle){return nStyle.name}) if (titles.indexOf(newStyleTitle) == -1){ nStyle = document.outline.namedStyles.add(newStyleTitle) nStyle.set(Style.Attribute.FontFillColor, Color.red) } else { alertTitle = "NAMING CONFLICT" alertMessage = "A named style title “" + newStyleTitle + "” already exists." new Alert(alertTitle, alertMessage).show(function(result){}) }
omnioutliner:///omnijs-run?script=newStyleTitle%20%3D%20%27IMPORTANT%27%0AnStyles%20%3D%20document%2Eoutline%2EnamedStyles%2Eall%0Atitles%20%3D%20nStyles%2Emap%28function%28nStyle%29%7Breturn%20nStyle%2Ename%7D%29%0Aif%20%28titles%2EindexOf%28newStyleTitle%29%20%3D%3D%20-1%29%7B%0A%09nStyle%20%3D%20document%2Eoutline%2EnamedStyles%2Eadd%28newStyleTitle%29%0A%09nStyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Ered%29%0A%7D%20else%20%7B%0A%09alertTitle%20%3D%20%22NAMING%20CONFLICT%22%0A%09alertMessage%20%3D%20%22A%20named%20style%20title%20%E2%80%9C%22%20%2B%20newStyleTitle%20%2B%20%22%E2%80%9D%20already%20exists%2E%22%0A%09new%20Alert%28alertTitle%2C%20alertMessage%29%2Eshow%28function%28result%29%7B%7D%29%0A%7D

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.

styleTitle = 'iPad Link' if (document.outline.namedStyles.byName(styleTitle) === null){ nStyle = document.outline.namedStyles.add(styleTitle) nStyle.set(Style.Attribute.FontFillColor, Color.blue) url = URL.fromString("https://www.apple.com/ipad") nStyle.set(Style.Attribute.Link, url) } var aStyle = document.outline.namedStyles.byName(styleTitle)
nStyles = document.outline.namedStyles nStyle = nStyles.byName('IMPORTANT') if (nStyle != null){ nStyles.moveStyles([nStyle], nStyles.beginning) }
omnioutliner:///omnijs-run?script=nStyles%20%3D%20document%2Eoutline%2EnamedStyles%0AnStyle%20%3D%20nStyles%2EbyName%28%27IMPORTANT%27%29%0Aif%20%28nStyle%20%21%3D%20null%29%7B%0A%09nStyles%2EmoveStyles%28%5BnStyle%5D%2C%20nStyles%2Ebeginning%29%0A%7D

Applying Named Styles

The following examples demonstrate how to apply a named style to text objects in an outline document:

styleTitle = 'Red Text' if (document.outline.namedStyles.byName(styleTitle) === null){ nStyle = document.outline.namedStyles.add(styleTitle) nStyle.set(Style.Attribute.FontFillColor, Color.red) } var aStyle = document.outline.namedStyles.byName(styleTitle) topicColumn = document.outline.outlineColumn rootItem.apply(function(item){ if (item != rootItem){ textObj = item.valueForColumn(topicColumn) textObj.style.setStyle(aStyle) } })
omnioutliner://localhost/omnijs-run?script=styleTitle%20%3D%20%27Red%20Text%27%0Aif%20%28document%2Eoutline%2EnamedStyles%2EbyName%28styleTitle%29%20%3D%3D%3D%20null%29%7B%0A%09nStyle%20%3D%20document%2Eoutline%2EnamedStyles%2Eadd%28styleTitle%29%0A%09nStyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Ered%29%0A%7D%0Avar%20aStyle%20%3D%20document%2Eoutline%2EnamedStyles%2EbyName%28styleTitle%29%0A%0AtopicColumn%20%3D%20document%2Eoutline%2EoutlineColumn%0ArootItem%2Eapply%28function%28item%29%7B%0A%09if%20%28item%20%21%3D%20rootItem%29%7B%0A%09%09textObj%20%3D%20item%2EvalueForColumn%28topicColumn%29%0A%09%09textObj%2Estyle%2EsetStyle%28aStyle%29%0A%09%7D%0A%7D%29

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.

styleTitle = 'iPad Link' if (document.outline.namedStyles.byName(styleTitle) === null){ nStyle = document.outline.namedStyles.add(styleTitle) nStyle.set(Style.Attribute.FontFillColor, Color.blue) url = URL.fromString("https://www.apple.com/ipad") nStyle.set(Style.Attribute.Link, url) } var aStyle = document.outline.namedStyles.byName(styleTitle) topicColumn = document.outline.outlineColumn rootItem.apply(function(item){ if (item != rootItem){ textObj = item.valueForColumn(topicColumn) wordRanges = textObj.ranges(TextComponent.Words) wordRanges.forEach(function(range){ if(textObj.textInRange(range).string === 'iPad'){ size = textObj.styleForRange(range).get(Style.Attribute.FontSize) aStyle.set(Style.Attribute.FontSize, size) textObj.styleForRange(range).setStyle(aStyle) } }) } })
omnioutliner://localhost/omnijs-run?script=styleTitle%20%3D%20%27iPad%20Link%27%0Aif%20%28document%2Eoutline%2EnamedStyles%2EbyName%28styleTitle%29%20%3D%3D%3D%20null%29%7B%0A%09nStyle%20%3D%20document%2Eoutline%2EnamedStyles%2Eadd%28styleTitle%29%0A%09nStyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Eblue%29%0A%09url%20%3D%20URL%2EfromString%28%22https%3A%2F%2Fwww%2Eapple%2Ecom%2Fipad%22%29%0A%09nStyle%2Eset%28Style%2EAttribute%2ELink%2C%20url%29%0A%7D%0Avar%20aStyle%20%3D%20document%2Eoutline%2EnamedStyles%2EbyName%28styleTitle%29%0A%0AtopicColumn%20%3D%20document%2Eoutline%2EoutlineColumn%0ArootItem%2Eapply%28function%28item%29%7B%0A%09if%20%28item%20%21%3D%20rootItem%29%7B%0A%09%09textObj%20%3D%20item%2EvalueForColumn%28topicColumn%29%0A%09%09wordRanges%20%3D%20textObj%2Eranges%28TextComponent%2EWords%29%0A%09%09wordRanges%2EforEach%28function%28range%29%7B%0A%09%09%09if%28textObj%2EtextInRange%28range%29%2Estring%20%3D%3D%3D%20%27iPad%27%29%7B%0A%09%09%09%09size%20%3D%20textObj%2EstyleForRange%28range%29%2Eget%28Style%2EAttribute%2EFontSize%29%0A%09%09%09%09aStyle%2Eset%28Style%2EAttribute%2EFontSize%2C%20size%29%0A%09%09%09%09textObj%2EstyleForRange%28range%29%2EsetStyle%28aStyle%29%0A%09%09%09%7D%0A%09%09%7D%29%0A%09%7D%0A%7D%29

Here is a link to the Add “iPad” Links script saved as an OmniOutliner solitary action:

macOS_deviceTo 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.

macOS_deviceTo 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.

UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER