Selection

The properties of the Selection class provide scripting access to the objects that are currently selected in the application interface. These objects include the following:

Accessing the Selection

In OmniGraffle, the selection is a property of the Window class. In OmniOutliner, the selection is a property of the Editor class, and so must be accessed accordingly, appeneded to a statement ending with an instance of the Editor class, usually the first or current editor:

An instance of the Selection class contains references to the objects listed above, which are accessed by appending them to the selection instance:

Using these selection objects, scripts can provide functionality targeted at the objects selected by the user.

Examples

Here’s the basic script for processing selected items (rows):

var items = document.editors.selection.items items.forEach(function(item){ // processing statements go here })

and here’s an expanded version of the previous script that converts the notes of selected items into follow-on rows (siblings):

var items = document.editors[0].selection.items items.forEach(function(item){ var itemNote = item.note var itemParent = item.parent itemParent.addChild( item.after, function(row){ row.topic = itemNote } ) item.note = "" })
omnioutliner://localhost/omnijs-run?script=items%20%3D%20document%2Eeditors%5B0%5D%2Eselection%2Eitems%0Aitems%2EforEach%28function%28item%29%7B%0A%09itemNote%20%3D%20item%2Enote%0A%09itemParent%20%3D%20item%2Eparent%0A%09itemParent%2EaddChild%28%0A%09%09item%2Eafter%2C%0A%09%09function%28row%29%7B%0A%09%09%09row%2Etopic%20%3D%20itemNote%0A%09%09%7D%0A%09%29%0A%09item%2Enote%20%3D%20%22%22%0A%7D%29
/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.oo.notes-to-rows", "version": "1.0", "description": "Convert notes of the selected rows into follow-on rows (siblings).", "label": "Notes to Sibling Rows", "shortLabel": "Notes to Rows" }*/ (() => { var action = new PlugIn.Action(function(selection, sender) { // action code // selection options: columns, document, editor, items, nodes, styles selection.items.forEach(function(item){ var itemNote = item.note var itemParent = item.parent itemParent.addChild( item.after, function(row){ row.topic = itemNote } ) item.note = "" }) }); action.validate = function(selection, sender) { // validation code // selection options: columns, document, editor, items, nodes, styles if(selection.nodes.length > 0){return true} else {return false} }; return action; })();
notes-to-follow-on-rows

The following script uses the columns property of the selection instance to adjust the widths of the selected columns to be the arithmetic mean (average) of their widths:

var editor = document.editors[0] var selectedColumns = editor.selection.columns var columnCount = selectedColumns.length if (columnCount === 1){throw new Error('single column')} var widths = selectedColumns.map(function(col){ return editor.widthForColumn(col) }) var total = widths.reduce( function(total,num){return total + num}, 0) var avgWidth = total/columnCount avgWidth = Number(avgWidth.toFixed(0)) selectedColumns.forEach( function(col){editor.setWidthForColumn(col,avgWidth)} )
/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.oo.balance-columns", "version": "1.0", "description": "Adjust the width of selected columns to be the same.", "label": "Balance Widths of Selected Columns", "shortLabel": "Balance Column Widths" }*/ (() => { var action = new PlugIn.Action(function(selection, sender) { // action code // selection options: columns, document, editor, items, nodes, styles var selectedColumns = selection.columns var editor = selection.editor var columnCount = selectedColumns.length var widths = selectedColumns.map(col => { return editor.widthForColumn(col) }) var total = widths.reduce(function(total,num){return total + num},0) var avgWidth = total/columnCount avgWidth = Number(avgWidth.toFixed(0)) selectedColumns.forEach( function(col){editor.setWidthForColumn(col,avgWidth)} ) }); action.validate = function(selection, sender) { // validation code // selection options: columns, document, editor, items, nodes, styles return (selection.columns.length > 1) }; return action; })();
omnioutliner:///omnijs-run?script=editor%20%3D%20document%2Eeditors%5B0%5D%0AselectedColumns%20%3D%20editor%2Eselection%2Ecolumns%0AcolumnCount%20%3D%20selectedColumns%2Elength%0Aif%20%28columnCount%20%3D%3D%3D%201%29%7Bthrow%20new%20Error%28%27single%20column%27%29%7D%0Awidths%20%3D%20selectedColumns%2Emap%28function%28col%29%7B%0A%09return%20editor%2EwidthForColumn%28col%29%0A%7D%29%0Atotal%20%3D%20widths%2Ereduce%28%0A%09function%28total%2Cnum%29%7Breturn%20total%20%2B%20num%7D%2C%20%0A0%29%0AavgWidth%20%3D%20total%2FcolumnCount%0AavgWidth%20%3D%20Number%28avgWidth%2EtoFixed%280%29%29%0AselectedColumns%2EforEach%28%0A%09function%28col%29%7Beditor%2EsetWidthForColumn%28col%2CavgWidth%29%7D%0A%29
column-balance-before-after

An example script that applies a focus to the selected items:

var editor = document.editors[0] editor.focusedItems = editor.selection.items
omnioutliner:///omnijs-run?script=editor%20%3D%20document%2Eeditors%5B0%5D%0Aeditor%2EfocusedItems%20%3D%20editor%2Eselection%2Eitems
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