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 items or columns, 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.

Class Functions

Here are the class functions of the Document class. They can be used to create new outline documents.

omnioutliner://localhost/omnijs-run?script=Document%2EmakeNewAndShow%28newDoc%20%3D%3E%20%7B%0D%09baseItem%20%3D%20newDoc%2Eeditors%5B0%5D%2ErootNode%2Eobject%0D%09baseItem%2EaddChild%28null%2Citem%20%3D%3E%20%7Bitem%2Etopic%20%3D%20%27HELLO%20WORLD%27%7D%29%0D%09newDoc%2Eoutline%2EbaseStyle%2Eclear%28%29%0D%09newDoc%2Eoutline%2EbaseStyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Ered%29%0D%7D%29
Create a New Document
 

Document.makeNewAndShow(newDoc => { baseItem = newDoc.editors[0].rootNode.object baseItem.addChild(null,item => {item.topic = 'HELLO WORLD'}) newDoc.outline.baseStyle.clear() newDoc.outline.baseStyle.set(Style.Attribute.FontFillColor, Color.red) })

NOTE: the above example uses methods from the Style class

New document with a row displaying “Hello World” in red text.

A similar version of the previous script but calling the makeNewAndShow( ) method asynchronously from within an asynchronous function wrapper:

Create a New Document (asynchronous wrapper)


(async () => { try { newDoc = await Document.makeNewAndShow() baseItem = newDoc.editors[0].rootNode.object baseItem.addChild(null,item => {item.topic = 'HELLO WORLD'}) newDoc.outline.baseStyle.clear() newDoc.outline.baseStyle.set(Style.Attribute.FontFillColor, Color.red) } catch(err){ new Alert(err.name, err.message).show() } })();

The following script uses functions of the Editor and Pasteboard classes to create a new document containing the contents of the selected rows of the current document:

omnioutliner://localhost/omnijs-run?script=%28async%20%28%29%20%3D%3E%20%7B%0D%09try%20%7B%0D%09%09nodes%20%3D%20document%2Eeditors%5B0%5D%2EselectedNodes%0D%09%09pb%20%3D%20Pasteboard%2EmakeUnique%28%29%0D%09%09document%2Eeditors%5B0%5D%2EcopyNodes%28nodes%2C%20pb%29%0D%09%09newDoc%20%3D%20await%20Document%2EmakeNewAndShow%28%29%0D%09%09newDoc%2Eeditors%5B0%5D%2Epaste%28pb%29%0D%09%7D%0D%09catch%28err%29%7B%0D%09%09new%20Alert%28err%2Ename%2C%20err%2Emessage%29%2Eshow%28%29%0D%09%7D%0D%7D%29%28%29%3B
New Document with Content of Selected Rows
 

(async () => { try { nodes = document.editors[0].selectedNodes pb = Pasteboard.makeUnique() document.editors[0].copyNodes(nodes, pb) newDoc = await Document.makeNewAndShow() newDoc.editors[0].paste(pb) } catch(err){ new Alert(err.name, err.message).show() } })();

Instance Functions

The following functions can be applied to instances of the Document class.

Document Properties

The document class has a small set of properties:

name Property

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.

The following script statement will return the name of the current document without any file extension:

omnioutliner://localhost/omnijs-run?script=documentName%20%3D%20document%2Ename%2Ereplace%28%2F%5C%2E%5B%5E%2F%2E%5D%2B%24%2F%2C%20%22%22%29%0Dconsole%2Elog%28%22DOCUMENT%20NAME%3A%22%2C%20documentName%29
name Property
 

documentName = document.name.replace(/\.[^/.]+$/, "") console.log("DOCUMENT NAME:", documentName)

writableTypes Property

The following script statement will return a list of the available writable file types. [See Document Export section for detailed examples]

writableTypes Property


document.writableTypes.join("\n") //--> "com.omnigroup.omnioutliner.xmlooutline com.omnigroup.omnioutliner.ooutline com.omnigroup.omnioutliner.oooutline com.omnigroup.omnioutliner.xmlooutline-package com.omnigroup.omnioutliner.otemplate com.omnigroup.omnioutliner.otemplate-package com.omnigroup.omnioutliner.oo3 com.omnigroup.omnioutliner.oo3-package com.omnigroup.omnioutliner.oo3template com.omnigroup.omnioutliner.oo3template-package org.opml.opml org.opml.opmltemplate public.rtf com.symantec.MORE.text public.plain-text com.apple.rtfd com.omnigroup.word.openxml.indented com.omnigroup.word.openxml.outline com.omnigroup.OmniOutliner.SimpleHTMLExport.HTML com.microsoft.powerpoint.openxml.presentation com.omnigroup.OmniOutliner.OO3HTMLExport.OO3HTMLDynamic com.omnigroup.OmniOutliner.HTMLExport.HTMLDynamic com.microsoft.excel.openxml.document public.comma-separated-values-text"

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.

canUndo -> undo


if(document.canUndo){document.undo()}

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.

canRedo -> redo


if(document.canRedo){document.redo()}

Document Close

Close this document.

Close Current Document


document.close()

When attempting to close the current document, a crash may occur if the close() function is called within the script being executed by the current document:

New Document Closing Previous One (Unsafe)


(async () => { try { newDoc = await Document.makeNewAndShow() document.close() } catch(err){ new Alert(err.name, err.message).show() } })();

Instead, place the close() function targeting the current document inside the handler being run in the new document’s context:

New Document Closing Previous One (Safe)


currentDoc = document Document.makeNewAndShow(newDoc => { currentDoc.close() })

Document Save

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

Save


document.save()
 

FileType

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

The FileType instance properties:

Scripts for logging type information in the Console window:

readableTypes


FileType.readableTypes.forEach(function(fType){ console.log('NAME: ' + fType.displayName) console.log('IDENTIFIER: ' + fType.identifier) console.log('EXTENSIONS: ' + fType.pathExtensions) console.log('----------------------------') })
readableTypes


NAME: org.opml.opmltemplate IDENTIFIER: org.opml.opmltemplate EXTENSIONS: opmltemplate ---------------------------- NAME: org.opml.opml IDENTIFIER: org.opml.opml EXTENSIONS: opml ---------------------------- NAME: com.symantec.more IDENTIFIER: com.symantec.more EXTENSIONS: more ---------------------------- NAME: com.omnigroup.omnioutliner.oo3template IDENTIFIER: com.omnigroup.omnioutliner.oo3template EXTENSIONS: oo3template ---------------------------- NAME: com.omnigroup.omnioutliner.oo3 IDENTIFIER: com.omnigroup.omnioutliner.oo3 EXTENSIONS: oo3 ---------------------------- NAME: com.omnigroup.omnioutliner.otemplate IDENTIFIER: com.omnigroup.omnioutliner.otemplate EXTENSIONS: otemplate ---------------------------- NAME: com.apple.xcode.strings-text IDENTIFIER: com.apple.xcode.strings-text EXTENSIONS: strings ---------------------------- NAME: com.omnigroup.omnioutliner.xmlooutline-package IDENTIFIER: com.omnigroup.omnioutliner.xmlooutline-package EXTENSIONS: ooutline ---------------------------- NAME: com.omnigroup.omnioutliner.xmlooutline IDENTIFIER: com.omnigroup.omnioutliner.xmlooutline EXTENSIONS: ooutline ---------------------------- NAME: com.omnigroup.omnioutliner.otemplate-package IDENTIFIER: com.omnigroup.omnioutliner.otemplate-package EXTENSIONS: otemplate ---------------------------- NAME: com.omnigroup.omnioutliner.oo3template-package IDENTIFIER: com.omnigroup.omnioutliner.oo3template-package EXTENSIONS: oo3template ---------------------------- NAME: com.apple.property-list IDENTIFIER: com.apple.property-list EXTENSIONS: plist ---------------------------- NAME: com.omnigroup.omnioutliner.oo3-package IDENTIFIER: com.omnigroup.omnioutliner.oo3-package EXTENSIONS: oo3 ----------------------------
writableTypes


FileType.writableTypes.forEach(function(fType){ console.log('NAME: ' + fType.displayName) console.log('IDENTIFIER: ' + fType.identifier) console.log('EXTENSIONS: ' + fType.pathExtensions) console.log('----------------------------') })
writableTypes


NAME: com.omnigroup.omnioutliner.oo3-package IDENTIFIER: com.omnigroup.omnioutliner.oo3-package EXTENSIONS: oo3 ---------------------------- NAME: org.opml.opml IDENTIFIER: org.opml.opml EXTENSIONS: opml ---------------------------- NAME: com.omnigroup.omnioutliner.xmlooutline-package IDENTIFIER: com.omnigroup.omnioutliner.xmlooutline-package EXTENSIONS: ooutline ---------------------------- NAME: com.omnigroup.omnioutliner.otemplate IDENTIFIER: com.omnigroup.omnioutliner.otemplate EXTENSIONS: otemplate ---------------------------- NAME: com.omnigroup.omnioutliner.oo3template IDENTIFIER: com.omnigroup.omnioutliner.oo3template EXTENSIONS: oo3template ---------------------------- NAME: com.omnigroup.omnioutliner.oo3template-package IDENTIFIER: com.omnigroup.omnioutliner.oo3template-package EXTENSIONS: oo3template ---------------------------- NAME: com.omnigroup.omnioutliner.oo3 IDENTIFIER: com.omnigroup.omnioutliner.oo3 EXTENSIONS: oo3 ---------------------------- NAME: com.omnigroup.omnioutliner.xmlooutline IDENTIFIER: com.omnigroup.omnioutliner.xmlooutline EXTENSIONS: ooutline ---------------------------- NAME: org.opml.opmltemplate IDENTIFIER: org.opml.opmltemplate EXTENSIONS: opmltemplate ---------------------------- NAME: com.omnigroup.omnioutliner.otemplate-package IDENTIFIER: com.omnigroup.omnioutliner.otemplate-package EXTENSIONS: otemplate ----------------------------