This Shortcuts example will prompt the user to search for a nearby business and then append a Maps link for the chosen business, to the note of the selected project or task.
This shortcut will prompt the user to search for a nearby business and then append a Maps link for the chosen business, to the note of the selected project or task.
1 “Open App” action • Make OmniFocus the active application.
2 “Omni Automation Script” action • This action will execute its Omni Automation script.
3 Script Code • A script that returns the value of the primaryKey property of the single selected task or project 4 If a single project or task is not selected, an error message will be displayed to the user, and the workflow halted.
5 Map Search • A map search input dialog will be displayed, passing the matched items to the following action. NOTE: by default this action is set to search for local businesses within a 2-mile radius of your current location. Adjust these settings to match your preferred values.
6 List of Matches • Presents a list of matching businesses, the chosen list item is passed to the following action.
7 Map Link (URL) • An Apple Maps link to the selected business is generated.
8 Data Dictionary • A data dictionary (record) is created containing the passed values from the previous actions: the ID of selected task/project; the Maps URL of the chosen business.
9 Data Input Socket • The data dictionary is placed in the Data Input Socket of the “Omni Automation Script” action.
10 Omni Automation script • This script uses the argument.input parameter to extract the data passed within the data dictionary, and then uses that data to located the selected OmniFocus task/project and append the Maps link to its note.
Here are the Omni Automation scripts used in this Shortcuts workflow:
Return Identifier of Selected Task or Project(async () => { 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] } return selectedItem.id.primaryKey } else { throw { name: "Selection Issue", message: "Please select a single project or task." } } } catch(err){ if(!err.message.includes("cancelled")){ await new Alert(err.name, err.message).show() } throw `${err.name}\n${err.message}` }})();
Process Passed Data Dictionaryvar url = argument.input.mapsURLvar ID = argument.input.objectIDvar item = Task.byIdentifier(ID)if (!item){item = Project.byIdentifier(ID)}if(item.note.length === 0){ item.appendStringToNote(url)} else { item.appendStringToNote( "\n" + url)}