OmniFocus: New Calendar Event for Item
Using the selected task or project, the iOS/iPadOS Share Sheet, Shortcuts, and Omni Automation, a new event is created in the Calendar app containing the parameters and data from the selected OmniFocus item.
Video 1: New Event for Item |
Using the selected task or project, the iOS/iPadOS Share Sheet, Shortcuts, and Omni Automation, a new event is created in the Calendar app containing the parameters and data from the selected OmniFocus item. |
|
Omni Automation Script
This script serves two purposes:
- Filter the passed-in URLs to derive the unique identifier for the selected object, and create an object reference to the object. If the selected item is not a project or task (perhaps it’s a folder!), an error is displayed to the user and the workflow is stopped.
- Create and pass a JavaScript dictionary of relevant properties and values, and pass it as a string to the next action in the workflow.
Retrieve and Pass Properties of Selected Item
(async () => {
try {
// INPUT IS URL OR ARRAY OF URL
var passedData = argument.input
if (typeof passedData === "string"){passedData = [passedData]}
var url = ""
passedData.forEach(item => {
if (
item.startsWith('omnifocus:') &&
!item.includes('?') &&
!item.includes(',')
){url = item}
})
segments = url.split("/")
var id = segments[4]
var type = segments[3]
if(type === "task"){
// OBJECT REFERENCE TO ITEM
var item = Task.byIdentifier(id)
var type = "task"
if(!item){
var item = Project.byIdentifier(id)
var type = "project"
}
// IF A DICTIONARY IS TO BE PASSED
itemProperties = new Object()
itemProperties["primaryKey"] = id
itemProperties["type"] = type
itemProperties["link"] = "omnifocus:///task/" + id
itemProperties["name"] = item.name
itemProperties["note"] = item.note || ""
itemProperties["due"] = item.dueDate
var duration = item.estimatedMinutes
if(duration){
itemProperties["duration"] = duration
} else {
itemProperties["duration"] = 0
}
// PASS ITEM DICTIONARY
return JSON.stringify(itemProperties)
} else {
throw {
name: "Selection Issue",
message: "Please select a single task or project."
}
}
}
catch(err){
if(!err.message.includes("cancelled")){
await new Alert(err.name, err.message).show()
}
throw `${err.name}\n${err.message}`
}
})();