This shortcut template for iOS/iPadOS demonstrates how to trigger a shortcut for the selected item (task, project, or folder) using the iOS/iPadOS Share Sheet.
1 Input Settings • The shortcut is set to receive URLs as input. If there is no input, and error message is displayed. When a task is selected in iOS/iPadOS and the shortcut run from the Share Sheet, a OmniFocus URL link (omnifocus:///task/1a2ws3erW) to the selected item is passed to the shortcut.
2 Shortcut Settings • The shortcut is set to appear in the iOS/iPadOS Share Sheet.
3 “Omni Automation Script” action • The resulting URL(s) from the shortcut input is placed into the Data Input Socket of “Omni Automation Script” action.
4 Retrieve Input • The argument.input parameter is used to retrieve the URL data placed in the Data Input Socket. The URL of the selected task, project, or folder is in the passed input. To retrieve the type and ID of the selected task, the URL is divided into segments using the split() function.
5 Dictionary • The script creates a JavaScript object (dictionary) using the type, ID, name, and other properties of the selected item. This dictionary is then converted into a string using the JSON.stringify() function and is passed to “Get Dictionary from Input” action, which stores returns it as a dictionary.
6 “Show Result” action • Displays the created dictionary for the shared item.
(⬇ see below ) The shortcut appears on the Share Sheet
1 Selected Item • This shortcut template is designed to work with a selected task, project, or folder, when the shortcut is triggered via the iOS/iPadOS Share Sheet
2 Shortcut on Share Sheet • The published shortcut is accessed via the Share Sheet.
3 Item Dictionary • The resulting dictionary of item properties that can be used with other actions.
Omni Automation Script
Here is the Omni Automation script used by the shortcut:
Derive Item Reference from Share Sheet// INPUT IS URL STRING OR ARRAY OF URLvar passedData = argument.inputif (typeof passedData === "string"){passedData = [passedData]}var url = ""passedData.forEach(item => { if ( item.startsWith('omnifocus:') && !item.includes('?') && !item.includes(',') ){url = item}})segments = url.split("/")var id = segments[4]var type = segments[3]if(type === "task"){ // OBJECT REFERENCE TO ITEM var item = Task.byIdentifier(id) var type = "task" if(!item){ var item = Project.byIdentifier(id) var type = "project" } // IF A DICTIONARY IS TO BE PASSED itemProperties = new Object() itemProperties["primaryKey"] = id itemProperties["type"] = type itemProperties["link"] = "omnifocus:///task/" + id itemProperties["name"] = item.name itemProperties["note"] = item.note || "" itemProperties["due"] = item.dueDate} else if (type === "folder"){ // OBJECT REFERENCE TO ITEM var item = Folder.byIdentifier(id) // IF A DICTIONARY IS TO BE PASSED itemProperties = new Object() itemProperties["primaryKey"] = id itemProperties["type"] = type itemProperties["link"] = "omnifocus:///folder/" + id itemProperties["name"] = item.name}// PASS ITEM DICTIONARYJSON.stringify(itemProperties)