×

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.

DOWNLOAD SHORTCUT

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)}) }

 1  “Open App” action • This action makes OmniFocus the active application.

 2  “Omni Automation Script” action • This action contains an Omni Automation script targeting the OmniFocus application.

 3  Omni Automation script • This script is designed to check for a single selected OmniFocus task or project. If the selection requirements are not met, and error message is displayed and the shortcut is halted.

 4  Return Object’s ID • Passing the unique identifier of the selected object, which is the value of its primaryKey property. (related documentation)

 5  “Dictate Text” action • Shortcuts’ built-in action for enabling the user to pass dictated text in a shortcut.

dictate-note-workflow

 6  “Dictionary” action • Shortcuts’ built-in action for creating a dictionary of keys and their corresponding values. This dictionary will contain the selected OmniFocus object’s unique identifier (primaryKey), as well as the note text dictated by the user.

 7  Data Input Socket • The created dictionary is placed in the Data Input Socket of a second “Omni Automation Script” action for OmniFocus.

 8  Omni Automation script • This asynchronous function presents a options menu to the user for them to select the editing method used with the selected object’s note: Replace or Append to the existing note.

 X  Retrieve passed data • The argument.input parameter is used to retrieve the passed identifier and the dictated text, which are then used to edit the note of the selected object accorgingly.

(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}` } })();