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.
New Document | ||
01 | Document.makeNewAndShow(function(doc){ | |
02 | baseItem = doc.editors[0].rootNode.object | |
03 | baseItem.addChild(null,function(item){item.topic = 'HELLO WORLD'}) | |
04 | doc.outline.baseStyle.clear() | |
05 | doc.outline.baseStyle.set(Style.Attribute.FontFillColor, Color.red) | |
06 | }) |
NOTE: the above example uses methods from the Style class
Document Properties
The document class has a small set of properties:
canRedo (boolean r/o) • Whether there are currently any actions that can be redone.
canUndo (boolean r/o) • Whether there are currently any actions that can be undone.
fileType (String or nil r/o see FileType) • The file type identifier the document uses when saving, if set.
name (String r/o) • Name of the document.
writableTypes (Array of String r/o) • A list of all of the file types that this document can be written as.
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.
01 | document.name | |
02 | --> Construction Outline |
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.
Document Undo | ||
01 | 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.
Document Redo | ||
01 | if(document.canRedo){document.redo()} |
Writable Types
The value of this property is a list of all of the file types that this document can be written as.
Writable Types | ||
01 | document.writableTypes | |
02 | //--> 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, com.apple.news.opml, org.opml.opmltemplate, public.rtf, public.plain-text, com.apple.rtfd, com.omnigroup.word.openxml.indented.Microsoft Word (indented), com.omnigroup.word.openxml.outline.Microsoft Word (outline), com.omnigroup.OmniOutliner.SimpleHTMLExport.HTML, org.openxmlformats.presentationml.presentation.PowerPoint 2012 Format (pptx), com.omnigroup.OmniOutliner.OO3HTMLExport.OO3HTMLDynamic, com.omnigroup.OmniOutliner.HTMLExport.HTMLDynamic, com.microsoft.excel.openxml.document.Excel 2010 Format (xlsx), com.omnigroup.OmniOutliner.CSVExport.CSV | |
03 |
Instance Functions
These are the methods that can be performed with a document.
undo() • Undo the last done action.
redo() • Redo the last undone action.
close(didCancel:Function or nil) • Close this document. If for some reason the document cannot be closed, the didCancel function may be called at some point in the future, with the original document as the single argument. For example, on the Mac the user may review unsaved changes and may cancel the close operation. If the document is closed, the didCancel function will not be called at all.
save() • Save this document.
fileWrapper(type:String or nil) --> FileWrapper • Deprecated: Please use makeFileWrapper(…) instead. Returns a new FileWrapper representing the contents of the document formatted as the specified type, or its current fileType if a null is passed for the type. (see export page for examples)
makeFileWrapper(baseName:String, type:String or null) → (Promise) • Generates a FileWrapper representing the contents of the document formatted as the specified type, or its current fileType if a null is passed for the type. Returns a JavaScript Promise that will yield the file wrapper or an error. The returned file wrapper will have a name based off the given baseName and the default path extension for the requested file type. [see the Document Export page for example of using this command]
show(resultFunction:Function or nil) • Presents the document, ordering the window forward on macOS, and possibly closing the existing document and opening the new on on iOS.
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.
Document Undo | ||
01 | 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.
Document Redo | ||
01 | if(document.canRedo){document.redo()} |
Document Close
Close this document.
Document Close | ||
01 | document.close() |
New Document Closing Current Document | ||
01 | var oldDoc = document | |
02 | Document.makeNewAndShow(function(newDoc){ | |
03 | oldDoc.close() | |
04 | }) |
Optionally, a script can know if the close process was cancelled by the user in a save dialog:
Close Document | ||
01 | document.close(function(doc){console.log('Close cancelled')}) |
Document Save
The save() method performs the standard save action with the document.
Document Save | ||
01 | document.save() |
FileType
The FileType class properties are the value for the fileType property of the Document class:
readableTypes (Array of FileType r/o) • The list of FileTypes that can be read by this application.
writableTypes (Array of FileType r/o) • The list of FileTypes that can be written by this application (though some documents may be exportable only in a subset of these types).
Readable File Types | ||
01 | FileType.readableTypes | |
02 | //--> [object FileType: com.omnigroup.omnioutliner.xmlooutline], | |
03 |
Writable File Types | ||
01 | FileType.writableTypes | |
02 | //--> [object FileType: com.omnigroup.omnioutliner.xmlooutline], |
The FileType instance properties:
displayName (String r/o) • Returns a human-readable description of the file type.
identifier (String r/o) • Returns a unique identifier for a file type, suitable for archiving or encoding in scripts.
pathExtensions (Array of String r/o) • The list of filesystem path extensions used by this file type.
And scripts for gathering information about each file type:
Readable File Types Info | ||
01 | FileType.readableTypes.forEach(function(fType){ | |
02 | console.log('NAME: ' + fType.displayName) | |
03 | console.log('IDENTIFIER: ' + fType.identifier) | |
04 | console.log('EXTENSIONS: ' + fType.pathExtensions) | |
05 | console.log('----------------------------') | |
06 | }) |
Writable File Types Info | ||
01 | FileType.writableTypes.forEach(function(fType){ | |
02 | console.log('NAME: ' + fType.displayName) | |
03 | console.log('IDENTIFIER: ' + fType.identifier) | |
04 | console.log('EXTENSIONS: ' + fType.pathExtensions) | |
05 | console.log('----------------------------') | |
06 | }) |
This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.