DatabaseObject

The DatabaseObject class is a generalized class containing the various elements used by the database to order and store your data, including: folders, projects, tasks, and tags. These database objects share a common id property that is most often used in conjuction with the built-in OmniFocus URL support to reveal one or more DatebaseObjects in the main window.

Instance Properties

The DatabaseObject class has one property:

ObjectIdentifier Class

An instance of the ObjectIdentifier class is returned as the value of the id property of the DatabaseObject class. An instance of the ObjectIdentifier class has two properties:

You can incorporate the id and primaryKey properties with the built-in OmniFocus URL support to reveal one or more DatebaseObjects in the main window:

tag = tagNamed("West") if(tag){ urlStr = "omnifocus:///tag/" + tag.id.primaryKey URL.fromString(urlStr).open() }
folder = folderNamed("Fall") if(folder){ urlStr = "omnifocus:///folder/" + folder.id.primaryKey URL.fromString(urlStr).open() }
project = projectNamed("My Project") if(project){ urlStr = "omnifocus:///task/" + project.id.primaryKey URL.fromString(urlStr).open() }

To reveal more than one database object, append a comma-delimited list of primaryKeys to the calling URL:

keys = new Array() inbox.forEach(task=>{ if (task.name.includes(" Car")){keys.push(task.id.primaryKey)} }) if (keys){ urlStr = "omnifocus:///task/" + keys.join(",") URL.fromString(urlStr).open() }
taskName = "Drive Car" matches = flattenedTasks.filter(item => { return item.name.toUpperCase() === taskName.toUpperCase() }) if (matches.length > 0){ keys = matches.map(task => {return task.id.primaryKey}) urlStr = "omnifocus:///task/" + keys.join(",") URL.fromString(urlStr).open() }

DatabaseObject: DatedObject

The DatedObject class (a sub-class of the DatabaseObject class) contains elements that track date values referencing the element’s creation and modification. These properties apply to tasks, tags, folders, and projects (for projects, the root task of the project has the dates for the project).

Instance Properties

The DatedObject class has two properties:

project = projectNamed("My Project") if (project){ console.log(project.task.added) console.log(project.task.modified) }

An example script for creating a new project whose creation date is midnight of the current date:

project = new Project("NEW PROJECT") project.task.added = new Date(new Date().setHours(0,0,0,0))

DatedObject: ActiveObject

The ActiveObject class (a sub-class of the DatedObject class) contains elements that are active.

Instance Properties

The ActiveObject class has two properties:

project = projectNamed("My Project") if (project){ project.task.active = false }
var tag = tagNamed("Camera-Ready") if(tag){tag.active = false} var tag = tagNamed("Camera-Ready") if(tag){tag.active = true}

Link-Back Task

Here’s a plug-in that uses the id and primaryKey properties of the DatabaseObject class to create a new task whose notes field contains a link to the currently selected task.

DISCLAIMER