OmniFocus: Search Notes App for Tag
This shortcut searches the Notes application for notes tagged with the chosen tag assigned to the currently selected OmniFocus task or project.
Video 1: Search Notes for Tag |
This shortcut searches the Notes application for notes tagged with the chosen tag assigned to the currently selected OmniFocus task or project. |
|
The Shortcut Workflow:
1 “Omni Automation Script” action • The Omni Automation script checks for a single selected task or project and then presents a menu of titles of the tags assigned to the selected element. In addition, an option is provided to place a link to the selected element on the clipboard for pasting into the found note. The result of this action is the chosen tag title, prepended with a hash character (#) which is used by the Notes application to delineate tags.
2 “Find Notes” action • This action searches the Notes database for notes that contain the passed tag.
3 “Show Notes” action • This action will display and select the note chosen from the list of found notes containing the search tag.

The Omni Automation Script
1-64 Asynchronous Wrapper • Since this script displays UI to the user, it is wrapped in an asynchronous function that enables the script to complete its processed before passing control back to the workflow.
3-18 Selected Element • The Omni Automation script checks for a single selected task or project. If none is found, an error message is posted to the user.
19-25 Assigned Tags • The script generates a list of the titles of the tags assigned to the selected element. If no tags are assigned, an error message is posted to the user.
27-49 Action Form • A form dialog containing a menu of tag titles and a checkbox for approving copying an element reference link is presented to the user and the results of the form are extracted.
51-54 Element Reference Link • If chosen by the user, a URL to the selected task or project is generated and placed on the clipboard.
56 Return Tag • The chosen tag is returned to the workflow in Notes format (prepended with a hash character).
Search Notes App for Tag
(async () => {
try {
sel = document.windows[0].selection
selCount = sel.tasks.length + sel.projects.length
if(selCount === 1){
if (sel.tasks.length === 1){
selectedItem = sel.tasks[0]
itemType = "task"
} else {
selectedItem = sel.projects[0]
itemType = "project"
}
} else {
throw {
name: "Selection Issue",
message: "Please select a single project or task."
}
}
tagTitles = selectedItem.tags.map(tag => tag.name)
if(tagTitles.length === 0){
throw {
name: "No Tags",
message: `The selected ${itemType} has no assigned tags.`
}
}
tagTitlesMenu = new Form.Field.Option(
"tagTitle",
null,
tagTitles,
tagTitles,
tagTitles[0]
)
checkSwitchField = new Form.Field.Checkbox(
"shouldCopyLinkURL",
`Place a link to selected ${itemType} on the clipboard`,
false
)
inputForm = new Form()
inputForm.addField(tagTitlesMenu)
inputForm.addField(checkSwitchField)
formPrompt = "Choose tag to search for in Notes:"
buttonTitle = "Continue"
formObject = await inputForm.show(formPrompt,buttonTitle)
tagTitle = formObject.values["tagTitle"]
shouldCopyLinkURL = formObject.values["shouldCopyLinkURL"]
if(shouldCopyLinkURL){
url = URL.fromString("omnifocus://task/" + selectedItem.id.primaryKey)
Pasteboard.general.URL = url
}
return String("#" + tagTitle)
}
catch(err){
if(!err.message.includes("cancelled")){
await new Alert(err.name, err.message).show()
}
throw `${err.name}\n${err.message}`
}
})();