Focus

The Focus command (Shift-Command–F)(⇧⌘F) in the View menu brings the currently selected row and its children (or rows and their children, if more than one are selected) into focus by hiding everything else in your OmniOutliner document.

the Unfocus command (Option-Shift-Command–F)(⌥⌘F) removes the previously assigned Focus.

Typically, these commands are triggered by the user after selecting the rows to focused. In scripts, you can focus an array of rows regardless of their selection status. In this section you’ll learn how to write a script to focus the rows whose checkboxes are selected.

DO THIS ►

Select the checkbox of every other planet in the outline:

checked-items

To enter focused-mode with the checked item via a script, the script must examine the state of every item, and then pass references to the checked items to editor to display them focused. Here’s the script:

editor = document.editors[0] checkColumn = document.outline.statusColumn checkedItems = new Array() editor.rootNode.children.forEach( function(node){ state = node.valueForColumn(checkColumn) if (state === State.Checked){ checkedItems.push(node.object) } } ) editor.focusedItems = checkedItems
omnioutliner:///omnijs-run?script=editor%20%3D%20document%2Eeditors%5B0%5D%0AcheckColumn%20%3D%20document%2Eoutline%2EstatusColumn%0AcheckedItems%20%3D%20new%20Array%28%29%0Aeditor%2ErootNode%2Echildren%2EforEach%28%0A%09function%28node%29%7B%0A%09%09state%20%3D%20node%2EvalueForColumn%28checkColumn%29%0A%09%09if%20%28state%20%3D%3D%3D%20State%2EChecked%29%7B%0A%09%09%09checkedItems%2Epush%28node%2Eobject%29%0A%09%09%7D%0A%09%7D%0A%29%0Aeditor%2EfocusedItems%20%3D%20checkedItems

 1  Store a reference to the current editor in the variable titled: editor

 2  Store a reference to the status column (checkboxes) in a variable titled: checkColumn

 3  Create a new array in which to place references to checked items.

 4-11  Use the forEach() method to iterate the child nodes of the rootNode.

 6  Store the state of the iterated node by using the valueForColumn() method to determine the state of the status column cell.

 7-9  A conditional for those items whose checkbox is selected. If true, then add a reference to the item (row) to the array. Note the use of the node’s object property that returns a reference to a node’s corresponding item.

 12  Focus the checked items by setting the value of the current editor’s focusedItems property to the array.

DO THIS ►

Copy and paste the example script into the console and execute it by pressing the Return key.

The result will be a focused group of items whose checkboxes are selected. All unchecked items will be hidden.

focused-items

To return the outline to a normal unfocused state, simply set the value of the current editor’s focusedItems property to an empty array: ([ ])

document.editors[0].focusedItems = []
omnioutliner:///omnijs-run?script=document%2Eeditors%5B0%5D%2EfocusedItems%20%3D%20%5B%5D

What’s Next?

In the next section, you’ll learn how to apply text styling properties to outline elements using scripts.

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