Document and Data Export

OmniFocus supports the export of documents and data to files of various formats. This section examines how to create File Wrappers in preparation for the export of documents and content.

Documentation regarding the other classes involved in the saving and export of OmniFocus 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 instances of the FileWrapper class.

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 OmniOmniFocus, 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 FileWrapper types supported in OmniFocus.

For documentation of both readable and writable file types in OmniFocus, visit the FileType shared topic.

The following example script generates an array of the identifiers that comprise the value for the writableTypes property:

omnifocus://localhost/omnijs-run?script=try%7Btypes%20%3D%20document%2EwritableTypes%2Emap%28%28type%29%3D%3E%7B%20return%20%22%5C%22%22%20%2B%20type%20%2B%20%22%5C%22%22%7D%29%0Atypes%20%3D%20%22%5B%22%20%2B%20types%2Ejoin%28%22%2C%5Cn%22%29%20%2B%20%22%5D%22%0Aconsole%2Elog%28types%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
OmniFocus FileWrapper Writable Types
 

types = document.writableTypes.map(type => { return "\"" + type + "\"" }) types = "[" + types.join(",\n") + "]" console.log(types) //--> ["com.omnigroup.omnifocus.filetype.ofocus", "com.omnigroup.omnifocus2.export-filetype.plain-text", "com.omnigroup.omnifocus2.export-filetype.html", "com.omnigroup.omnifocus2.export-filetype.comma-separated-values", "com.omnigroup.omnifocus2.export-filetype.comma-separated-values-unicode", "com.omnigroup.omnifocus.filetype.ofocus-backup"]

A writable type identifier is used with the makeFileWrapper() function when creating a new file wrapper instance:

New FileWrapper Instance


(async () => { try { fileTypeID = "com.omnigroup.omnifocus.filetype.ofocus" baseName = "OF Backup" wrapper = await document.makeFileWrapper(baseName, fileTypeID) // WRAPPER PROCESSING STATEMENTS } catch(err){ new Alert(err.name, err.message).show() } })();

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:

Base 64 Encode New File Wrapper Instance


(async () => { try { fileTypeID = "com.omnigroup.omnifocus.filetype.ofocus" baseName = "OF Backup" wrapper = await document.makeFileWrapper(baseName, fileTypeID) encodedData = wrapper.contents.toBase64() console.log(encodedData) } catch(err){ new Alert(err.name, err.message).show() } })();

Class Functions

The class functions for the FileWrapper class:

Instance Functions

The instance functions for the FileWrapper class:

FileWrapper.Type

The class properties of a FileWrapper.Type:

Export Types

Here are the various export formats with their corresponding file type identifiers:

OmniFocus Document (.ofocus)
This is an ordinary OmniFocus document, like the one that you use as your database. If you open such a file in OmniFocus, it appears in its own window and you can work with it normally, but settings specific to your database (such as custom perspectives and View options) don’t come along with it.
com.omnigroup.omnifocus.filetype.ofocus
Plain Text (.txt)
This is a lightweight plain-text representation of your data, able to be opened in the text editor of your choice. OmniFocus’s plain text export is inspired by TaskPaper, the light to-do application from Hog Bay Software. As such the output should be roughly compatible and able to be imported to TaskPaper with a minimum of fuss.
com.omnigroup.omnifocus2.export-filetype.plain-text
Simple HTML (.html)
This is a single-file HTML representation of your data; the stylesheet and even the icons are embedded in the HTML. If you are proficient with CSS, you should be able to restyle the result however you like.
com.omnigroup.omnifocus2.export-filetype.html
Comma Separated Values (.csv)
CSV is a common syntax for applications old and new on all platforms: all of your data in a plain text file with its columns separated by commas. Once you have your data in CSV format, it’s easy to run scripts on it, convert it to some other format, or open it in applications that understand it (like OmniPlan). If you’re having trouble persuading other applications to read the non-ASCII characters in your CSV file, such as accented letters or non-Roman characters, try exporting with the UTF–16 CSV option.
omnigroup.omnifocus2.export-filetype.comma-separated-values
omnigroup.omnifocus2.export-filetype.comma-separated-values-unicode
Backup Document (.ofocus-backup)
This export option creates a file in a format (.ofocus-backup) that is essentially the same as the standard OmniFocus database format, with one key difference.
Unlike a standard OmniFocus database file, when you open a backup in OmniFocus, the option to Revert to This Backup appears in a notice bar beneath the toolbar. Click this button to replace your local default database with the database contained in the backup.
omnigroup.omnifocus.filetype.ofocus-backup

Saving/Exporting a Specific Document Type

The following Omni Automation script demonstrates how to save a backup OmniFocus document to file. Similar procedures are used by all Omni applications to export data and documents to file.

Detailed documentation regarding the FileType class, and its use to generate application-specific FileWrappers, can be found in the FileType topic.

omnifocus://localhost/omnijs-run?script=var%20fmtr%20%3D%20Formatter%2EDate%2EwithFormat%28%27eee%2DMMM%2Ddd%2Dyyyy%27%29%0Avar%20defaultName%20%3D%20%22OF%20Backup%20%22%20%2B%20fmtr%2EstringFromDate%28new%20Date%28%29%29%0Avar%20fileTypeID%20%3D%20%27com%2Eomnigroup%2Eomnifocus%2Efiletype%2Eofocus%2Dbackup%27%0Avar%20wrapperPromise%20%3D%20document%2EmakeFileWrapper%28defaultName%2C%20fileTypeID%29%0AwrapperPromise%2Ethen%28wrapper%20%3D%3E%20%7B%0A%09var%20filesaver%20%3D%20new%20FileSaver%28%29%0A%09var%20filetype%20%3D%20new%20FileType%28fileTypeID%29%0A%09filesaver%2Etypes%20%3D%20%5Bfiletype%5D%0A%09filesaver%2Eshow%28wrapper%29%0A%7D%29
Save OmniFocus Backup Document
 

(async () => { try { fmtr = Formatter.Date.withFormat('eee-MMM-dd-yyyy') defaultName = "OF Backup " + fmtr.stringFromDate(new Date()) fileTypeID = 'com.omnigroup.omnifocus.filetype.ofocus-backup' wrapper = await document.makeFileWrapper(defaultName, fileTypeID) filesaver = new FileSaver() filetype = new FileType(fileTypeID) filesaver.types = [filetype] urlObj = await filesaver.show(wrapper) } catch(err){ new Alert(err.name, err.message).show() } })();

AirDrop OmniFocus Database Backup

Here is an example script that use the SharePanel class to AirDrop a backup copy of the OmniFocus document:

omnifocus://localhost/omnijs-run?script=try%7Bvar%20fileTypeID%20%3D%20%27com%2Eomnigroup%2Eomnifocus%2Efiletype%2Eofocus%2Dbackup%27%0Avar%20defaultName%20%3D%20%22OmniFocus%20DB%20Backup%22%0Avar%20wrapperPromise%20%3D%20document%2EmakeFileWrapper%28defaultName%2C%20fileTypeID%29%0AwrapperPromise%2Ethen%28function%28wrapper%29%7B%0A%09new%20SharePanel%28%5Bwrapper%5D%29%2Eshow%28%29%0A%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
AirDrop Backup of OmniFocus Document
 

(async () => { try { fileTypeID = 'com.omnigroup.omnifocus.filetype.ofocus-backup' defaultName = "OmniFocus DB Backup" wrapper = await document.makeFileWrapper(defaultName, fileTypeID) new SharePanel([wrapper]).show() } catch(err){ new Alert(err.name, err.message).show() } })();

When the script is run, the share sheet appears from which you can select the option to AirDrop the exported file:

share-sheet airdrop-dialog  

Share Task Attachments

Here’s a plug-in variation of the previous script example, that displays share sheet for the attachments of the selected task:

Share Task Attachements
  

/*{ "author": "Otto Automator", "targets": ["omnifocus"], "type": "action", "identifier": "com.omni-automation.of.share-attachments", "version": "1.0", "description": "Displays a share sheet for sharing the task attachments.", "label": "Share Attachments", "mediumLabel": "Share Attachments", "paletteLabel": "Share Attachments", "image": "square.and.arrow.up.on.square" }*/ (() => { const action = new PlugIn.Action(function(selection, sender){ task = selection.tasks[0] new SharePanel(task.attachments).show() }); action.validate = function(selection, sender){ return ( selection.tasks.length === 1 && selection.tasks[0].attachments.length !== 0 ) }; return action; })();