OmniFocus: Dictate Note for Selected Item
A shortcut that either replaces or appends the contents of the note of the selecte OmniFocus task or project with the user’s dictated text.
This shortcut incorporates two instances of the “Omni Automation Script” action. The script for the first action is provided below:
Return Primary Key (ID) of Selected Task or Project
try {
var sel = document.windows[0].selection
var selCount = sel.tasks.length + sel.projects.length
if(selCount === 1){
if (sel.tasks.length === 1){
var selectedItem = sel.tasks[0]
} else {
var selectedItem = sel.projects[0]
}
} else {
throw {
name: "Selection Issue",
message: "Please select a single project or task."
}
}
selectedItem.id.primaryKey
}
catch(err){
var alertPromise = new Alert(err.name, err.message).show()
alertPromise.then(buttonIndex => {throw new Error(-128)})
}
(below) The script of the second instance of the “Omni Automation Script” action prompts the user to choose the method for editing the existing note, and then retrieves the passed OmniFocus object ID and the dictated text in order to locate and edit the note of the selected OmniFocus object. Note that the unique identifier (primaryKey) of the selected object is returned by the function, thereby passing it back to the parent shortcut workflow.
Change the Note Content
(async () => {
try {
var editMethodMenu = new Form.Field.Option(
"editMethod",
null,
["Replace", "Append"],
["Replace", "Append"],
"Replace"
)
var inputForm = new Form()
inputForm.addField(editMethodMenu)
var formPrompt = "Use dictation to:"
var formObject = await inputForm.show(formPrompt, "Continue")
var editMethod = formObject.values["editMethod"]
var passedID = argument.input.objectID
var dictatedText = argument.input.dictation
var selectedItem = Task.byIdentifier(passedID)
if(!selectedItem){selectedItem = Project.byIdentifier(passedID)}
if(editMethod === "Replace"){
selectedItem.note = dictatedText
} else {
selectedItem.note = selectedItem.note + "\n" + dictatedText
}
return selectedItem.id.primaryKey
}
catch(err){
if(!err.message.includes("cancelled")){
await new Alert(err.name, err.message).show()
}
throw `${err.name}\n${err.message}`
}
})();