OmniOutliner & Omni Automation

OmniOutliner is a flexible program for creating, collecting, and organizing information. Whether you’re keeping track of tasks for a project or putting together an outline for a book or research paper, OmniOutliner has everything you need to get the details just right. The Professional Edition adds a full suite of styling, customization, and management tools to get your outlines looking just the way you want.

And with Omni Automation and OmniOutliner, you can streamline how you work, delivering enhanced productivity and creative uses of data and design.

The Application Object

In Omni Automation, the OmniOutliner application object has properties (name, version) and elements (documents, windows). In a script, the application object is represented as: app

If you entered just “app” in the OmniOutliner console window and executed the line, the result would be a reference to the application object:

To get the name of the OS the app is running on:

Properties: name

The value of the name property of the application object is a string representing the name of the OmniGraffle application.

The value of the application name property is read-only.

Properties: Key Down Properties

The following application properties can be used by scripts to determine if the standard modifier keys are pressed when the script is run:

Properties: version

The value of the version property of the application object is a string representing the version number of the OmniOutliner application.

The value of the application version property is read-only.

To create a new version object:

To extract the version string from a version object:

Comparing Versions

There are four methods you can use for comparing version objects:

Here are functions demonstrating their use:

function isBeforeCurVers(versStrToCheck){ curVersStr = app.version curVers = new Version(curVersStr) versToCheck = new Version(versStrToCheck) result = versToCheck.isBefore(curVers) console.log(versStrToCheck + ' is before ' + curVersStr + " = " + result) return result } function isEqualToCurVers(versStrToCheck){ curVersStr = app.version curVers = new Version(curVersStr) versToCheck = new Version(versStrToCheck) result = versToCheck.equals(curVers) console.log(versStrToCheck + ' equals ' + curVersStr + " = " + result) return result } function isAtLeastCurVers(versStrToCheck){ curVersStr = app.version curVers = new Version(curVersStr) versToCheck = new Version(versStrToCheck) result = versToCheck.atLeast(curVers) console.log(versStrToCheck + ' is at least ' + curVersStr + " = " + result) return result } function isAfterCurVers(versStrToCheck){ curVersStr = app.version curVers = new Version(curVersStr) versToCheck = new Version(versStrToCheck) result = versToCheck.isAfter(curVers) console.log(versStrToCheck + ' is after ' + curVersStr + " = " + result) return result }

Open an Existing Document

To open an OmniOutliner document file, a file URL is passed to the openDocument application method. This handler attempts to open the specified document and to return a reference to it asynchronously. If the document is already open, the reference to the open document is passed along.

Note that due to platform sandboxing restrictions, opening the document may fail if the application doesn’t have currently permission to access the given file URL. The document, if any, that is associated with the calling script can be passed along to help grant permission to open the new document.

The passed in function will return two arguments: the first (result) will be either either the Document reference or an Error. On success, the second argument (wasOpen) is a Boolean value specifying whether the document was already open.

app.openDocument(document,fileURL,function(result,wasOpen){}

A an example, here is a script that uses the FilePicker class to prompt the user to locate and select an OmniOutliner document and then open the chosen document:

var picker = new FilePicker() picker.folders = false picker.multiple = false var aFileType = new FileType("com.omnigroup.omnioutliner.xmlooutline", "com.omnigroup.omnioutliner.xmlooutline-package") picker.types = [aFileType] var pickerPromise = picker.show() pickerPromise.then(function(urlsArray){ var fileURL = urlsArray[0] app.openDocument( document, fileURL, function(doc,wasOpen){ var baseItem = doc.editors[0].rootNode.object baseItem.addChild(null,function(item){item.topic = 'HELLO WORLD'}) } ) })
omnioutliner://localhost/omnijs-run?script=try%7Bvar%20picker%20%3D%20new%20FilePicker%28%29%0Apicker%2Efolders%20%3D%20false%0Apicker%2Emultiple%20%3D%20false%0Avar%20aFileType%20%3D%20new%20FileType%28%22com%2Eomnigroup%2Eomnioutliner%2Exmlooutline%22%2C%20%22com%2Eomnigroup%2Eomnioutliner%2Exmlooutline%2Dpackage%22%29%0Apicker%2Etypes%20%3D%20%5BaFileType%5D%0Avar%20pickerPromise%20%3D%20picker%2Eshow%28%29%0ApickerPromise%2Ethen%28function%28urlsArray%29%7B%0A%09var%20fileURL%20%3D%20urlsArray%5B0%5D%0A%09app%2EopenDocument%28%0A%09%09document%2C%0A%09%09fileURL%2C%0A%09%09function%28doc%2CwasOpen%29%7B%0A%09%09%09var%20baseItem%20%3D%20doc%2Eeditors%5B0%5D%2ErootNode%2Eobject%0A%09%09%09baseItem%2EaddChild%28null%2Cfunction%28item%29%7Bitem%2Etopic%20%3D%20%27HELLO%20WORLD%27%7D%29%0A%09%09%7D%0A%09%29%0A%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

 01  Create a new instance of the FilePicker class and store a reference to it in the variable: picker

 02-03  Set the properties of the file picker to select a single document file.

 04  Indicate the file types that can be selected within the file picker. In this case, the bundle and single-file version of the standard OmniOutliner document format.

 05  Set the file types for the file picker to the stored list of file types.

 06  Use the show() function to display the file picker. The resulting JavaScript promise object is stored in the variable: pickerPromise

 07-17  Use the then() method with the stored promise object to process the array of URLs chosen in the file picker.

 08  Since multiple selections were not allowed, the resulting file URL will be the first in the array of one.

 09-16  The OmniOutliner openDocument(…) is called on the application object, passing in the chosen file URL to the then(…) callback function.

 12-15  The callback function of the openDocument(…) command will pass-in a reference to the newly created document, and a boolean value indicating if it was already open.

 13  To create a new item at the start of the outline, a reference to the rootNode of the newly opened document is created by specifying the hierarchical chain: document > editors > rootNode. In most scripts that target the current document, you only need to use rootNode by itself, but since the target document is being addressed by a script running in another document’s model, you must include the target document in the rootNode reference. The object property of the rootNode will return a reference to its corresponding rootItem.

 14  The addItem(…) function is then called on the derived rootItem to create a new item (row) at the end of the outline.

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