Document Export

OmniOutliner supports the export of outlines to documents of various formats, such as to standard office, spreadsheet, text, and HTML formats.

This section examines how to create instances of the FileWrapper class in preparation for the export of documents and content.

Documentation regarding the other classes involved in the saving and export of OmniPlan documents can be found in FileTypes and FileSavers.

FileWrappers

If you think of an outline as a set of data, then it’s easy to understand that an outline’s data can be packaged in a variety of ways. Each “data package” has a set of parameters that determine how the outline data is stored or presented.

For example, one package may store the data as tabbed data, while another may store the outline data in XML format. Each of the supported file packaging formats has its own set of parameters. In terms of Omni Automation, these file packages are referred to as FileWrappers.

Each instance of the FileWrapper class has a unique type identifier that identifies that wrapper. To get a list of the export types supported by OmniOutliner, write a simple script to access the value of the writableTypes property of the Document class. The result will be an array of the identifiers for the FileWrappers supported in OmniOutliner.

NOTE: a complete list of all readable and writeable filetypes supported by OmniOutliner is available here.

A writable type is used when creating a new FileWrapper instance by using the makeFileWrapper(…) function of the Document class:

fileTypeID = "com.omnigroup.OmniOutliner.CSVExport.CSV" baseName = document.name wrapperPromise = document.makeFileWrapper(baseName, fileTypeID) wrapperPromise.then(function(wrapper){ console.log(wrapper) //--> [object FileWrapper: file, 2729 bytes] }) wrapperPromise.catch(function(err){ console.error(err.message) })

 01  The file type identifier for the desired export format.

 02  The name that should be used for the exported document. Note that if a file saver dialog is used in the export script, the user may change the provided file name. Also note that if the export format is HTML, the provided name will be used to name the folder containing the main HTML file and supporting files.

 03  The makeFileWrapper(…) function of the Document class is used to create a file wrapper instance. Since it make take some time to complete the creation of a complex file wrapper, the result of this command is a JavaScript promise object, whose resulting content will be processed elsewhere in the export script. The file name and file type ID (optional) are provided as function parameters. Note that if the optional type ID is not provided, the default file format is used automatically.

 05-08  The then(…) method of the Promise class is used to process the contents of the JavaScript promise created earlier in the script. The file wrapper generated by the previous makeFileWrapper(…) function is passed into this function so that it may processed by those statements placed within the function.

 10-12  The catch(…) method of the Promise class is called in the event that there is a problem with the creation of the file wrapper.

Instance Properties

Each FileWrapper instance has a set of supported properties, most of which have values that are read-only, with the exception of the preferredFilename property whose value can be set in a script.

The value of the contents property is a representation of the outline data, which can be manipulated using class and instance functions from the Data class, such as the toBase64() function shown in the following example:

fileTypeID = "com.omnigroup.OmniOutliner.CSVExport.CSV" baseName = document.name wrapperPromise = document.makeFileWrapper(baseName, fileTypeID) wrapperPromise.then(function(wrapper){ encodedData = wrapper.contents.toBase64() }) wrapperPromise.catch(function(err){ console.error(err.message) })

Class Functions

The class functions for the FileWrapper class:

fileName = "Cow.txt" textData = Data.fromString("How now brown cow") wrapper = FileWrapper.withContents(fileName, textData)

It may be desired to perform multiple exports of a document to files in a variety of formats. The withChildren(…) class function can be used to create a folder containing one or more exported documents.

docName = document.name var fileTypeID1 = "org.opml.opml" var fileTypeID2 = "com.omnigroup.OmniOutliner.CSVExport.CSV" wrapperPromise1 = document.makeFileWrapper(docName + ".opml", fileTypeID1) wrapperPromise2 = document.makeFileWrapper(docName + ".csv", fileTypeID2) promises = [wrapperPromise1,wrapperPromise2] Promise.all(promises).then(function(fileWrappers){ filesaver = new FileSaver() folderType = new FileType("public.folder") fileType1 = new FileType(fileTypeID1) fileType2 = new FileType(fileTypeID2) filesaver.types = [folderType, fileType1, fileType2] fldrwrapper = FileWrapper.withChildren("Export Folder",fileWrappers) fileSaverPromise = filesaver.show(fldrwrapper) fileSaverPromise.then(function(urlObj){ console.log(urlObj.string) // file url to directory }) fileSaverPromise.catch(function(err){ console.log(err.message) }) }).catch(function(err){ console.log("Error", err.message) })
omnioutliner://localhost/omnijs-run?script=try%7BdocName%20%3D%20document%2Ename%0A%0Avar%20fileTypeID1%20%3D%20%22org%2Eopml%2Eopml%22%0Avar%20fileTypeID2%20%3D%20%22com%2Eomnigroup%2EOmniOutliner%2ECSVExport%2ECSV%22%0AwrapperPromise1%20%3D%20document%2EmakeFileWrapper%28docName%20%2B%20%22%2Eopml%22%2C%20fileTypeID1%29%0AwrapperPromise2%20%3D%20document%2EmakeFileWrapper%28docName%20%2B%20%22%2Ecsv%22%2C%20fileTypeID2%29%0Apromises%20%3D%20%5BwrapperPromise1%2CwrapperPromise2%5D%0A%0APromise%2Eall%28promises%29%2Ethen%28function%28fileWrappers%29%7B%0A%0A%09filesaver%20%3D%20new%20FileSaver%28%29%0A%09folderType%20%3D%20new%20FileType%28%22public%2Efolder%22%29%0A%09fileType1%20%3D%20new%20FileType%28fileTypeID1%29%0A%09fileType2%20%3D%20new%20FileType%28fileTypeID2%29%0A%09filesaver%2Etypes%20%3D%20%5BfolderType%2C%20fileType1%2C%20fileType2%5D%0A%09fldrwrapper%20%3D%20FileWrapper%2EwithChildren%28%22Export%20Folder%22%2CfileWrappers%29%0A%09fileSaverPromise%20%3D%20filesaver%2Eshow%28fldrwrapper%29%0A%0A%09fileSaverPromise%2Ethen%28function%28urlObj%29%7B%0A%09%09console%2Elog%28urlObj%2Estring%29%20%2F%2F%20file%20url%20to%20directory%0A%09%7D%29%0A%0A%09fileSaverPromise%2Ecatch%28function%28err%29%7B%0A%09%09console%2Elog%28err%2Emessage%29%0A%09%7D%29%0A%09%0A%7D%29%2Ecatch%28function%28err%29%7B%0A%09console%2Elog%28%22Error%22%2C%20err%2Emessage%29%0A%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

 01  Get the name of the current OmniOutliner document.

 03-04  The file type identifiers for the desired exports, in this example they are: OPML (Outline Processor Markup Language), and CSV (Comma-Separated Values)

 05  The makeFileWrapper(…) function of the Document class is used to generate the first file wrapper, by using the document name appending with the appropriate export file extension, and the corresponding file type ID. The result is a JavaScript promise object.

 06  The makeFileWrapper(…) function of the Document class is used to generate the second file wrapper, by using the document name appending with the appropriate export file extension, and the corresponding file type ID. The result is a JavaScript promise object.

 07  An array of the generated JavaScript promise objects is stored in the variable: promises

 09-27  The all(…) method of the Promise class is completed when all of the promises passed into the function are ready for processing. The then(…) function is appended to all(…) function in order to process the passed promises.

 11  This example script incorporates the use of a file saver dialog to allow the user to choose the name and location for the folder that will contain the exported documents. A new instance of the FileSaver class is created and stored in the variable: filesaver

 12  Generate a file type object for a folder.

 13-14  Generate file type objects for the desired export file type IDs.

 15  Set the file types of the file saver object to the array of generated file types. Note that the array should always begin with the folder type object.

 16  The withChildren(…) function of the FileWrapper class generates a file wrapper object for the export folder by passing in the folder name and array of export file wrappers as the function’s parameters.

 17  The show(…) method is used to display the file saver dialog, and the result of the method is a JavaScript promise object that will eventually contain the URL to the exported folder.

 19-21  The then(…) function of the Promise class is automatically called after the user has completed the file saver dialog, with a URL object reference to the export folder being passed into the function.

 23-25  The catch(…) function of the Promise class is called if the file saver dialog is canceled.

Instance Functions

The instance functions for the FileWrapper class:

FileWrapper.Type

The class properties of a FileWrapper.Type:

As mentioned previously, here is a full explanation of the FileWrapper.Types supported by OmniOutliner:

Here are the various export formats with their corresponding FileWrapper.Type:

CSV
When exporting a multi-column outline as CSV, OmniOutliner saves the .csv file using standard comma-separated values (CSV) conventions (i.e., each column is separated by a comma, and text with spaces is placed within quotations).
com.omnigroup.OmniOutliner.CSVExport.CSV
Excel 2010 Format
Creates a .xlsx spreadsheet document capable of being read in Microsoft Excel 2010 (and other versions of Excel that support the format). This export option maps most closely to multi-column data outside OmniOutliner, and does its best to replicate styles between the two (within the limits of Excel).
com.microsoft.excel.openxml.document
HTML
Creates a like-named folder that contains an index.html file along with the necessary images and attachments that make up your OmniOutliner file. All of the styles you’ve used in OmniOutliner are converted to CSS and included in the index.html file.
com.omnigroup.OmniOutliner.SimpleHTMLExport.HTML
HTML (Dynamic)
This option gives you everything that comes with the basic HTML export, plus an added outliner.js file. This JavaScript file is what makes the file dynamic; you can open and close the sections of your document just as you would in OmniOutliner.
com.omnigroup.OmniOutliner.HTMLExport.HTMLDynamic
com.omnigroup.OmniOutliner.OO3HTMLExport.OO3HTMLDynamic
Microsoft Word (indented)
Creates a .docx file that opens in the default page layout view and retains the outline structure via indentation. This export option only includes the topic column, and is primarily useful for transitioning from an outline to a word processor (rather than duplicating OmniOutliner’s functionality in Word). Row level styles are converted to heading styles, and other styles are flattened and applied directly to text (Microsoft Word does not support OmniOutliner’s style model).
com.omnigroup.word.openxml.indented
Microsoft Word (outline)
Creates a .docx file that opens by default in Microsoft Word’s Outline view. Choose this option to export an outline that can be readily expanded upon in Word. This export option only includes the topic column.
com.omnigroup.word.openxml.outline
OmniOutliner Document
Exports a .ooutline file, the current default OmniOutliner file format (for OmniOutliner 5 and later).
com.omnigroup.omnioutliner.ooutline
com.omnigroup.omnioutliner.xmlooutline
com.omnigroup.omnioutliner.xmlooutline-package
OmniOutliner Template
Exports a .otemplate file which can be used as the base theme for other OmniOutliner outlines. This template format is not compatible with versions earlier than OmniOutliner 5.
com.omnigroup.omnioutliner.otemplate
com.omnigroup.omnioutliner.otemplate-package
OmniOutliner 3
Exports a .oo3 file which can be opened in either OmniOutliner 3 or 4 for Mac, and in OmniOutliner 1 for iPad and OmniOutliner 2 for iOS. These files are not compatible with OmniOutliner 2 for Mac and earlier. They can be opened in OmniOutliner 5, but must be updated to the newer .ooutline format before all editing features are available.
com.omnigroup.omnioutliner.oo3
com.omnigroup.omnioutliner.oo3-package
OmniOutliner 3 Template
Exports a .oo3template file which can be opened in either OmniOutliner 3 or 4. These files are not compatible with OmniOutliner 2 or earlier. They can be opened in OmniOutliner 5, but must be updated to the newer .otemplate format before they can be edited.
com.omnigroup.omnioutliner.oo3template
com.omnigroup.omnioutliner.oo3template-package
OPML (Outline Processor Markup Language)
Exports a .opml file, which retains the hierarchical structure of your outline. However, OPML files do not retain any of the styles or attachments you may have applied in OmniOutliner.
org.opml.opml
com.apple.news.opml
org.opml.opmltemplate
Plain Text (with tabs)
Exports a raw .txt file without any styles. Child rows and columns are aligned using tabs rather than spaces, making this type of export useful for importing into spreadsheet apps such as Numbers or Excel.
public.plain-text
PowerPoint 2012 Format (pptx)
OmniOutliner exports the contents of your outline in an XML format that PowerPoint 2012 can interpret and render. After exporting your outline as .pptx, you can then import the PowerPoint file into Apple’s Keynote app.
Each Level 1 row becomes a separate slide in the PowerPoint presentation, with its children listed on that slide, and notes become presenter notes. Very little styling is carried over from OmniOutliner (styles don’t match well between the two formats, so we err on the side of removing them).
Image attachments are placed on slides corresponding to their level in the hierarchy, but must be manually repositioned to the desired location on the slide.
org.openxmlformats.presentationml.presentation.PowerPoint 2012 Format (pptx)
RTF (Rich Text Format)
Exports a .rtf file, which retains all of the styles you’ve applied in OmniOutliner. RTF is a standard document format that most word processors, such as Word and macOS’s TextEdit app can open. Export to RTF if your Outliner document contains only text and numbers.
public.rtf
RTFD (Rich Text Format with Attachments)
Exports a .rtfd file, which retains all of the styles you’ve applied in OmniOutliner. What sets RTFD apart from RTF is that an RTFD file can contain attachments, such as any images, audio clips, or anything else you attach to your OmniOutliner file. Most word processors, such as Word, Pages, and macOS’s TextEdit can open .rtfd files.
com.apple.rtfd

Export Examples

Here are some examples of using FileWrappers to export OmniOutliner documents.

Here’s an Omni Automation script for creating a new task in OmniFocus with the current OmniOutliner document as an attachment. The script uses the integrated URL support in OmniFocus to create and run a URL link for creating tasks:

wrapperPromise = document.makeFileWrapper(document.name) wrapperPromise.then(function(wrapper){ taskName = encodeURIComponent(document.name) attachmentName = encodeURIComponent(wrapper.preferredFilename) encodedData = wrapper.contents.toBase64() urlStr = "omnifocus://localhost/add?name=" + taskName + "&attachment=" + encodedData + "&attachment-name=" + attachmentName URL.fromString(urlStr).open() }) wrapperPromise.catch(function(err){ console.error(err.message) })
omnioutliner://localhost/omnijs-run?script=try%7BwrapperPromise%20%3D%20document%2EmakeFileWrapper%28document%2Ename%29%0A%0AwrapperPromise%2Ethen%28function%28wrapper%29%7B%0A%09taskName%20%3D%20encodeURIComponent%28document%2Ename%29%0A%09attachmentName%20%3D%20encodeURIComponent%28wrapper%2EpreferredFilename%29%0A%09encodedData%20%3D%20wrapper%2Econtents%2EtoBase64%28%29%0A%09urlStr%20%3D%20%22omnifocus%3A%2F%2Flocalhost%2Fadd%3Fname%3D%22%20%2B%20taskName%20%2B%20%22%26attachment%3D%22%20%2B%20encodedData%20%2B%20%22%26attachment%2Dname%3D%22%20%2B%20attachmentName%0A%09URL%2EfromString%28urlStr%29%2Eopen%28%29%0A%7D%29%0A%0AwrapperPromise%2Ecatch%28function%28err%29%7B%0A%09console%2Eerror%28err%2Emessage%29%0A%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

 1  Use the makeFileWrapper(…) function of the Document class to generate a file wrapper, passing-in the name of the document to be used as the name of the export file. Since no export file type has been specified as a second parameter, the default export file format will be used. The result of the function is an instance of a JavaScript promise.

 03-09  The then(…) function of the Promise class is used to process the file wrapper once it has been created, and is passed into the function.

 04  Encode the document name to be used as the name of the task.

 05  Encode the document file name to be used as the attachment name.

 06  Encode the contents of the document in Base64 encoding format, which results in a string of URL approved characters.

 07  Combine the encoded elements into the URL format supported by OmniFocus.

 08  Convert the URL string into a URL object and execute it using the call() method.

More information about implementing the previous script as an Omni Automation action can be found here.

The following example script utilize the built-in eMail support in OmniOutliner to add export copies of the current document to new outgoing mail messages:

fileTypeID = "public.plain-text" baseName = document.name wrapperPromise = document.makeFileWrapper(baseName, fileTypeID) wrapperPromise.then(function(wrapper){ var email = new Email() email.subject = "Plain-Text Version of “" + document.name + "”" email.body = "Here is the plain-text version of the document for you!\n\n" email.fileWrappers = [wrapper] email.generate() }) wrapperPromise.catch(function(err){ console.error(err.message) })
omnioutliner://localhost/omnijs-run?script=try%7BfileTypeID%20%3D%20%22public%2Eplain%2Dtext%22%0AbaseName%20%3D%20document%2Ename%0AwrapperPromise%20%3D%20document%2EmakeFileWrapper%28baseName%2C%20fileTypeID%29%0A%0AwrapperPromise%2Ethen%28function%28wrapper%29%7B%0A%09outlineText%20%3D%20wrapper%2Econtents%2EtoString%28%29%0A%09var%20email%20%3D%20new%20Email%28%29%0A%09email%2Esubject%20%3D%20%22Plain%2DText%20Version%20of%20%E2%80%9C%22%20%2B%20document%2Ename%20%2B%20%22%E2%80%9D%22%0A%09email%2Ebody%20%3D%20%22Here%20is%20the%20plain%2Dtext%20version%20of%20the%20document%20for%20you%21%5Cn%5Cn%22%0A%09email%2EfileWrappers%20%3D%20%5Bwrapper%5D%0A%09email%2Egenerate%28%29%0A%7D%29%0A%0AwrapperPromise%2Ecatch%28function%28err%29%7B%0A%09console%2Eerror%28err%2Emessage%29%0A%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

You can use the contents property of the FileWrapper class to generate text content for an outgoing email message.

fileTypeID = "public.plain-text" baseName = document.name wrapperPromise = document.makeFileWrapper(baseName, fileTypeID) wrapperPromise.then(function(wrapper){ outlineText = wrapper.contents.toString() var email = new Email() email.subject = "Plain-Text Version of “" + document.name + "”" email.body = outlineText email.generate() }) wrapperPromise.catch(function(err){ console.error(err.message) })
omnioutliner://localhost/omnijs-run?script=try%7BfileTypeID%20%3D%20%22public%2Eplain%2Dtext%22%0AbaseName%20%3D%20document%2Ename%0AwrapperPromise%20%3D%20document%2EmakeFileWrapper%28baseName%2C%20fileTypeID%29%0A%0AwrapperPromise%2Ethen%28function%28wrapper%29%7B%0A%09outlineText%20%3D%20wrapper%2Econtents%2EtoString%28%29%0A%09var%20email%20%3D%20new%20Email%28%29%0A%09email%2Esubject%20%3D%20%22Plain%2DText%20Version%20of%20%E2%80%9C%22%20%2B%20document%2Ename%20%2B%20%22%E2%80%9D%22%0A%09email%2Ebody%20%3D%20outlineText%0A%09email%2Egenerate%28%29%0A%7D%29%0A%0AwrapperPromise%2Ecatch%28function%28err%29%7B%0A%09console%2Eerror%28err%2Emessage%29%0A%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
plain-email

Here’s an action that uses the same export technique to send the current outline to the Drafts application as plain text:

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.oo.export-outline-to-drafts-as-plain-text", "version": "1.0", "description": "This action will create a new document in the Drafts app with the contents of the outline in plain text format.", "label": "Drafts • Export to Drafts as Plain Text Outline", "shortLabel": "Export to Drafts" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // "com.apple.news.opml" "org.opml.opml" "public.plain-text" var fileTypeID = "public.plain-text" var baseName = "Outline" var wrapperPromise = document.makeFileWrapper(baseName, fileTypeID) wrapperPromise.then(function(wrapper){ var outlineText = wrapper.contents.toString() var encodedStr = encodeURIComponent(outlineText) var urlStr = "drafts5://x-callback-url/create?text=" + encodedStr var url = URL.fromString(urlStr) url.call(function(result){console.log(result)}) }) wrapperPromise.catch(function(err){ console.error(err.message) }) }); action.validate = function(selection, sender){ // validation code return (rootItem.descendants.length > 0) }; return action; })();

Export to HTML

The following Omni Automation plug-in will export the current outline to disk as a folder containing an HTML file with supporting files.

This plug-in uses an action form to prompt the user to select the export parameters to use. In addition, the action displays a file saver dialog from which the user determines the name and location to be used for the exported HTML folder.

The action code incorporates three uses of the JavaScript Promise class: 1) for form creation and display; 2) for generating the export file wrapper; and 3) for displaying and responding to the file saver dialog.

html-export-sheet
/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.oo-export-to-html", "version": "1.0", "description": "This action will export the current outline in either simple or dynamic HTML format.", "label": "Export to HTML", "shortLabel": "Export to HTML" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: columns, document, editor, items, nodes, outline, styles var inputForm = new Form() dynamicCheckbox = new Form.Field.Checkbox( "dynamicCheckbox", "Enable dynamic controls (disclosure triangles, checkboxes, etc.)", false ) openFileCheckbox = new Form.Field.Checkbox( "openFileCheckbox", "Display HTML after export", false ) inputForm.addField(dynamicCheckbox) inputForm.addField(openFileCheckbox) formPromise = inputForm.show("HTML Export:","Continue") formPromise.then(function(formObject){ var shouldExportAsDynamic = formObject.values['dynamicCheckbox'] if(shouldExportAsDynamic){ fileTypeID = "com.omnigroup.OmniOutliner.HTMLExport.HTMLDynamic" } else { fileTypeID = "com.omnigroup.OmniOutliner.SimpleHTMLExport.HTML" } var shouldDisplayAfterExport = formObject.values['openFileCheckbox'] var baseName = document.name wrapperPromise = document.makeFileWrapper(baseName, fileTypeID) wrapperPromise.then(function(wrapper){ filesaver = new FileSaver() fileSaverPromise = filesaver.show(wrapper) fileSaverPromise.then(function(urlObj){ console.log(urlObj.string) if(shouldDisplayAfterExport){ urlStr = urlObj.string + "/index.html" URL.fromString(urlStr).open() } }) fileSaverPromise.catch(function(err){ console.log(err.message) }) }).catch(function(err){console.log(err.message)}) }) }); action.validate = function(selection, sender){ // validation code // selection options: columns, document, editor, items, nodes, outline, styles return true }; return action; })();
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