Document

A Document is the top-level object in Omni Automation. For security reasons, scripts can only address the frontmost document, they cannot query for or address other documents that may be open. Unlike other classes of objects, such as graphics, that can be addressed by index, the “current document” is simply referenced as document instead of app.documents[0] in your scripts.

The following documentation describes how open, create, save, and close documents, as well as how to access a document’s properties.

Document.makeNewAndShow(function(doc){ baseItem = doc.editors[0].rootNode.object baseItem.addChild(null,function(item){item.topic = 'HELLO WORLD'}) doc.outline.baseStyle.clear() doc.outline.baseStyle.set(Style.Attribute.FontFillColor, Color.red) })
omnioutliner:///omnijs-run?script=Document%2EmakeNewAndShow%28function%28doc%29%7B%0A%09coreItem%20%3D%20doc%2Eeditors%5B0%5D%2ErootNode%2Eobject%0A%09coreItem%2EaddChild%28null%2Cfunction%28item%29%7Bitem%2Etopic%20%3D%20%27HELLO%20WORLD%27%7D%29%0A%09doc%2Eoutline%2EbaseStyle%2Eclear%28%29%0A%09doc%2Eoutline%2EbaseStyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Ered%29%0A%7D%29

NOTE: the above example uses methods from the Style class

Document Properties

The document class has a small set of properties:

Name

The read-only name property has a value that is the name of the OmniOutiner document as it appears in the title bar of the document window. On macOS, this value will reflect the value of the Finder’s file extension visibility setting, set in the file’s Information window.

Document Undo

If the value of the document’s canUndo property is true, then the undo() method can be used to undo the previous user or script action.

if(document.canUndo){document.undo()}
omnioutliner:///omnijs-run?script=if%28document%2EcanUndo%29%7Bdocument%2Eundo%28%29%7D

Document Redo

If the value of the document’s canRedo property is true, then the redo() method can be used to re-apply the previous user or script action.

if(document.canRedo){document.redo()}
omnioutliner:///omnijs-run?script=if%28document%2EcanRedo%29%7Bdocument%2Eredo%28%29%7D

Writable Types

The value of this property is a list of all of the file types that this document can be written as.

document.writableTypes

Instance Functions

These are the methods that can be performed with a document.

Document Undo

If the value of the document’s canUndo property is true, then the undo() method can be used to undo the previous user or script action.

if(document.canUndo){document.undo()}
omnioutliner:///omnijs-run?script=if%28document%2EcanUndo%29%7Bdocument%2Eundo%28%29%7D

Document Redo

If the value of the document’s canRedo property is true, then the redo() method can be used to re-apply the previous user or script action.

if(document.canRedo){document.redo()}
omnioutliner:///omnijs-run?script=if%28document%2EcanRedo%29%7Bdocument%2Eredo%28%29%7D

Document Close

Close this document.

document.close()
omnioutliner:///omnijs-run?script=document%2Eclose%28%29
var oldDoc = document Document.makeNewAndShow(function(newDoc){ oldDoc.close() })
omnioutliner:///omnijs-run?script=var%20oldDoc%20%3D%20document%0ADocument%2EmakeNewAndShow%28function%28newDoc%29%7B%0A%09oldDoc%2Eclose%28%29%0A%7D%29

Optionally, a script can know if the close process was cancelled by the user in a save dialog:

document.close(function(doc){console.log('Close cancelled')})

Document Save

The save() method performs the standard save action with the document.

document.save()
omnioutliner:///omnijs-run?script=document%2Esave%28%29
 

FileType

The FileType class properties are the value for the fileType property of the Document class:

The FileType instance properties:

And scripts for gathering information about each file type:

FileType.readableTypes.forEach(function(fType){ console.log('NAME: ' + fType.displayName) console.log('IDENTIFIER: ' + fType.identifier) console.log('EXTENSIONS: ' + fType.pathExtensions) console.log('----------------------------') })
FileType.writableTypes.forEach(function(fType){ console.log('NAME: ' + fType.displayName) console.log('IDENTIFIER: ' + fType.identifier) console.log('EXTENSIONS: ' + fType.pathExtensions) console.log('----------------------------') })
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