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.
Here are the scripting properties of a document:
canRedo (Boolean r/o) • Whether there are currently any actions that can be redone.
canUndo (Boolean) • Whether there are currently any actions that can be undone.
fileType (String or null r/o) • The file type identifier the document uses when saving, if set.
name (String or null r/o) • Document name.
windows (Array of DocumentWindow r/o) • The windows for this document.
writableTypes (Array of String r/o) • A list of all of the file types that this document can be written as.
|Get the Writeable File Types|
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.
makeNew(resultFunction:Function) • Create a new document, which can be populated with data and then presented. On iOS, if the document is not presented by the time the resultFunction returns, it will be closed. On macOS, the document will be left around and accessible to the running script. The resultFunction will be passed either the new document or an Error if there was a problem creating the document.
makeNewAndShow(resultFunction:Function) • Create a new document and presents it. The resultFunction will be passed either the new document or an Error if there was a problem creating the document.
|Show New Document|
|02||db = newDoc.windows.selection.database|
|03||tsk = new Task("NEW TASK", db.inbox.beginning)|
The supportive functions that can be called on an instance of the Document class.
close(didCancel:Function or null) • 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() • If the document has saved before, this function will save the document. If the document has not been previously saved, the display of a Save Sheet will be triggered in the application interface.
fileWrapper(type:String or null) → (FileWrapper) • (DEPRICATED) 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.
undo() • Undo the last done action.
redo() • Redo the last done action.
show(resultFunction:Function or null) • Presents the document, ordering the window forward on macOS, and possibly closing the existing document and opening the new on on iOS.
|Undo and Redo|
Opening an OmniFocus Document
Existing OmniFocus documents are opened using the openDocument(…) function of the Application class.
openDocument(from:Document or null, url:URL, completed:Function) • Attempts to open the specified document and return a reference to it asynchronously. If the document is already open, the reference is passed along. Note that due to platform sandboxing restrictions, opening the document may fail if the application doesn’t have currently permission to access the given URL. The document, if any, that is associated with the calling script can be passed along to help grant permission to open the new document. The passed in function will be passed two arguments. The first will be either either the Document or an Error. On success, the second argument is a Boolean specifying whether the document was already open.
|Open Document and Process InBox Tasks|
|01||var picker = new FilePicker()|
|02||picker.folders = false|
|03||picker.multiple = false|
|04||aFileType = new FileType("com.omnigroup.omnifocus.filetype.ofocus")|
|05||picker.types = [aFileType]|
|06||pickerPromise = picker.show()|
|09||fileURL = urlsArray|
|14||var db = doc.windows.selection.database|
|16||// task processing goes here|