Document

By default, OmniFocus is designed to use a single data source whose content is synced across your devices and is even accessible using a web-based HTML interface (browser) on non-Apple hardware.

In OmniFocus, a “document” provides a visual interface to the synced database that manages all of your projects, tasks, schedules, and information.

Document Properties

Here are the scripting properties of a document:

document.writableTypes.join('\n')

New Documents

Omni Automation scripts have the ability to create and manipulate new documents using the class and instance functions of the Document class. As OmniFocus is optimized for use with a single data source, the following functions are provided for theoretical and archival purposes.

Class Functions

Document.makeNewAndShow(function(newDoc){ db = newDoc.windows[0].selection.database tsk = new Task("NEW TASK",db.inbox.beginning) })

 01-04  The makeNewAndShow(…) function of the Document class is used to create and display a new document instance. Its result function is passed a reference to the newly created document.

 02  A reference to the backing database of the new document is stored in the variable: db

 03  A new task is created at the beginning of the Inbox of the new document.

Instance Functions

The supportive functions that can be called on an instance of the Document class.

Opening an OmniFocus Document

Existing OmniFocus documents are opened using the openDocument(…) function of the Application class.

The following example script uses the FilePicker and FileType classes to display a file picker dialog to the user, allowing them to choose the OmniFocus document to open and process.

var picker = new FilePicker() picker.folders = false picker.multiple = false aFileType = new FileType("com.omnigroup.omnifocus.filetype.ofocus") picker.types = [aFileType] pickerPromise = picker.show() pickerPromise.then((urlsArray)=>{ fileURL = urlsArray[0] app.openDocument( document, fileURL, function(doc,wasOpen){ var db = doc.windows[0].selection.database db.inbox.forEach((tsk)=>{ // task processing goes here }) } ) })

 01  Store a new instance of the FilePicker class in the variable: picker

 02-05  Set the parameters of the picker instance to allow the selection of a single OmniFocus file.

 06  Display the file picker dialog to the user. The result of doing so is a JavaScript Promise object that represents the completed result of the picker display.

 08-20  Call the then(…) function on the stored Promise object to process the chosen file, whose URL is passed into the callback function in an array of URLs containing a single URL item.

 09  Extract the file reference URL from the passed array of URLs.

 10-19  Call the openDocument(…) function on the Application object, passing-in the file reference URL. The processing function is passed a reference to the document once it has been opened.

 13-18  The callback function is passed a reference to the opened document.

 14  Use the selection property of the Document Window class to derive a reference to the backing database.

 15-17  Iterate any tasks in the InBox, performing actions on each one./p>

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