Document Selection

In many Omni Automation scripts, it is common practice for the script to process the items or objects the user has selected. Therefore, it is crucial that a script be able to identify the user selection. Here are techniques for determining either the selected nodes (editors) or the selected items (outline) in an OmniOutliner document.

Selected Nodes

To an editor, an item (row) is represented by a node. The selectedNodes property of the Editor class is provided as a way of getting an array (list) of the items (rows) currently selected in the document.

document.editors[0].selectedNodes

Selection Property (Selection Class)

The Editor class also has a selection property that can be used tp access a variety of selected objects including rows and columns. Its value is an instance of the Selection class.

Selected Items

References to selected outline items are acquired through the use of the selectedNodes property of the Editor class. The value of this property is an array of TreeNodes. The item represented by a TreeNode is accessed using the object property of the TreeNode.

Using the map() method is an efficient means for deriving an array of selected item objects from an array of selected nodes:

selectedItems = document.editors[0].selectedNodes.map(function(node){return node.object})

The Selection Parameter (actions)

Omni Automation actions, both solitary and those contained in plug-in bundles, provide an instance of the Selection class to the action and validation handlers in scripts. Each instance of the selection class includes values for each of the following instance properties:

Use of these Selection properties enables your scripts to target specific elements of the selection, such as selected rows, or selected columns as shown in the following example of a solitary action:

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Your Name or Company", "identifier": "com.youOrCompany.oo.actionName", "description": "Logs the titles of the selected columns.", "version": "1.0", "label": "Titles of Selected Columns", "shortLabel": "Selected Columns" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // selection options: columns, document, items, outline, or styles selection.columns.forEach(function(column){ if(column === selection.outline.noteColumn){ console.log('Notes: ' + column.title) } else if(column === selection.outline.outlineColumn){ console.log('Topics: ' + column.title) } else { console.log(column.title) } }) }); action.validate = function(selection, sender){ // selection options: columns, document, items, outline, or styles return (selection.columns.length > 0) }; return action; })();

To process the selected items (rows) in an OmniOutliner document, uses the items property of the Selection class to get an array of selected items from the passed instance of the Selection class:

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Your Name or Company", "identifier": "com.youOrCompany.oo.actionName", "description": "Logs the text of the selected items (rows).", "version": "1.0", "label": "Topics of Selected Items", "shortLabel": "Selected Topics" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // selection options: columns, document, items, outline, or styles selection.items.forEach(function(item){ console.log(item.topic) }) }); action.validate = function(selection, sender){ // selection options: columns, document, items, outline, or styles return (selection.items.length > 0) }; return action; })();

The OmniOutliner Template Generator

To make it easier to create your own custom OmniOutliner actions, we suggest using the OmniOutliner Action Template Generator

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