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:
The Omni Automation Script
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}`
}
})();