Generating OmniFocus Object References
The Shortcuts actions bundled with OmniFocus 4.5 include a set for generating object references to Database Objects from IDs or URLs passed as input to the specialized actions. These actions are: Get Project, Get Action (Task), Get Tag, Get Folder, and Get Perspective.
The “Get Object” Shortcut actions accept the IDs or URLs of OmniFocus objects as input and return an object reference to the OmniFocus object as a result.
Expanded Omni Automation support in OmniFocus 4.5
The DatabaseObject class has two instance properties, with the url property introduced in OmniFocus 4.5:
id (ObjectIdentifier r/o) • Returns the identifier object for this object.
url (URL or null r/o) • (4.5+) Returns a URL which links to this database object (tag, task, project, or folder), if one exists.
Also included in OmniFocus 4.5 is a new function for the Database class, named: objectForURL(…) This function can be used to convert the URL instance generated by the url property of a Database Object into an object reference.
An example of getting the url of a DatabaseObject, and then using the objectForURL(…) function of the Database class to derive an object reference to the object targeted by the URL:
Object’s URL
aTask = inbox[0]
if (aTask){
taskURL = aTask.url
//-> [object URL: omnifocus:///task/hX3u3oHdgEm]
objectForURL(taskURL)
//-> [object Task: Plan Party]
}
Using the new OmniFocus “Get Object” Shortcuts Actions
The following example Shortcuts workflows demonstrate using the “Get Project” action to generate an object reference from the selected project’s passed ID or URL:
Passing ID of Selected Project
The Omni Automation script used in the previous example:
Passing ID of Selected Project
try {
const selectedProjects = selection.projects
if(selectedProjects.length === 1){
selectedProjects[0].id.primaryKey
} else {
throw {
name: "Selection Issue",
message: "Please select a single project."
}
}
}
catch(err){
const alertPromise = new Alert(err.name, err.message).show()
alertPromise.then(result => {throw new Error(-128)})
}
Passing URL of Selected Project
(below) Clicking on the data input socket of the “Get Project” action to reveal and set the Data Type Picker type:
The Omni Automation script used in the previous example:
Passing URL of Selected Project
try {
const selectedProjects = selection.projects
if(selectedProjects.length === 1){
selectedProjects[0].task.url
} else {
throw {
name: "Selection Issue",
message: "Please select a single project."
}
}
}
catch(err){
const alertPromise = new Alert(err.name, err.message).show()
alertPromise.then(result => {throw new Error(-128)})
}
NOTE: The above script is passing a URL of the project’s root task:
selectedProjects[0].task.url
In OmniFocus 4.5, you may also pass the URL of the project itself:
selectedProjects[0].url
Integrating with Other Shortcuts Actions
Here’s an example workflow that passes the URL of a found project. Note that “Project URL” now is a data type option to be accepted as input: