Omni Automation and the Shortcuts App

shortcuts-logoThe new The Shortcuts app on iOS and iPadOS delivers new opportunities for automating the interaction of other apps with Omni suite of productivity software.

This section contains examples of integrating Omni Automation with Shortcuts and workflows.

Launch a Specified Workflow

The most fundamental way to interact with Shortcuts in an Omni app is to simply run an Omni Automation plug-in that opens a special Shortcuts URL to launch one of the workflows you’ve already installed on your device.

To use this plug-in, follow these steps:

NOTE: By default, this plug-in is designed to work with any of the Omni suite of productivity apps: OmniFocus, OmniGraffle, OmniPlan, and OmniOutliner. If you wish, you can edit the list of supported apps in line 3 to include just those Omni apps in which you want this plug-in to be available.

/*{ "type": "action", "targets": ["omnifocus","omnigraffle","omniplan","omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.all.launch-shortcut", "version": "1.0", "description": "This action will launch the specified Shortcuts workflow.", "label": "Launch Shortcut", "shortLabel": "Launch Shortcut" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code var workflowTitle = "Shortcuts Title" workflowTitle = encodeURIComponent(workflowTitle) urlStr = "shortcuts://run-workflow?name=" + workflowTitle URL.fromString(urlStr).open() }); action.validate = function(selection, sender){ return true }; return action; })();

Launch a Chosen Workflow

While the following action plug-in is functionally the same as the previous one, it provides the extra ability to choose the targeted workflow from a list of workflows when the plug-in is run.

launch-chosen-workflow-dialog

(⬆ see above )  1  Tap the default item to reveal the full list of specified workflows.  2  Select one of the workflow titles from the list of workflow titles  3  Tap “Continue” to launch the chosen workflow.

To use this plug-in, follow these steps:

NOTE: By default, this plug-in is designed to work with any of the Omni suite of productivity apps: OmniFocus, OmniGraffle, OmniPlan, and OmniOutliner. If you wish, you can edit the list of supported apps in line 3 to include just those Omni apps in which you want this plug-in to be available.

/*{ "type": "action", "targets": ["omnifocus","omnigraffle","omniplan","omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.all.launch-chosen-shortcut", "version": "1.0", "description": "This action will launch the Shortcuts workflow chosen from the presented form menu.", "label": "Launch Chosen Shortcut", "shortLabel": "Launch Chosen Shortcut" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code var menuItems = [ "Shortcut Workflow 1", "Shortcut Workflow 2", "Shortcut Workflow 3", "Shortcut Workflow 4" ] var menuIndexes = [] menuItems.forEach((item,index)=>{menuIndexes.push(index)}) var menuElement = new Form.Field.Option( "menuElement", null, menuIndexes, menuItems, 0 ) var inputForm = new Form() inputForm.addField(menuElement) var formPrompt = "Choose the Shortcut workflow:" var buttonTitle = "Continue" var formPromise = inputForm.show(formPrompt,buttonTitle) inputForm.validate = function(formObject){ return true } formPromise.then(function(formObject){ var menuIndex = formObject.values['menuElement'] var workflowTitle = menuItems[menuIndex] console.log(workflowTitle) workflowTitle = encodeURIComponent(workflowTitle) var urlStr = "shortcuts://run-workflow?name=" + workflowTitle URL.fromString(urlStr).open() }) formPromise.catch(function(err){ console.error("form cancelled", err.message) }) }); action.validate = function(selection, sender){ // validation code return true }; return action; })();

Run and Process Shortcut Workflow

In the following example plug-in, a specified Shortcuts workflow is launched and the result of the workflow is processed by the plug-in. This plug-in incorporates the same Shortcuts URL as the previous examples, but the URL is executed using the call() function of the URL class instead of the open() handler. The call() function employs an x-callback-url that enables the Shortcuts app to return the result of its workflow execution to the calling plug-in.

To adapt this plug-in for your use, follow these steps:

NOTE: By default, this plug-in is designed to work with any of the Omni suite of productivity apps: OmniFocus, OmniGraffle, OmniPlan, and OmniOutliner. If you wish, you can edit the list of supported apps in line 3 to include just those Omni apps in which you want this plug-in to be available.

/*{ "type": "action", "targets": ["omnifocus","omnigraffle","omniplan","omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.all.run-shortcut", "version": "1.0", "description": "This action will run the specified Shortcuts workflow and process the result passed back to the script.", "label": "Run Shortcut", "shortLabel": "Run Shortcut" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code var workflowTitle = "Shortcuts Title" workflowTitle = encodeURIComponent(workflowTitle) var urlStr = "shortcuts://run-workflow?name=" + workflowTitle var url = URL.fromString(urlStr) url.call(function(result){ console.log(result) // PROCESS RESULTS OF WORKFLOW }, function(error){ new Alert("SCRIPT ERROR", error).show() console.error(error) }) }); action.validate = function(selection, sender){ return true }; return action; })();

In this example a Shortcuts workflow titled “Address Book” is called to retrieve the name and phone number of a chosen contact:

address-book-workflow
/*{ "type": "action", "targets": ["omnifocus","omnigraffle","omniplan","omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.all.address-book", "version": "1.0", "description": "This action will run the specified Shortcuts workflow and process the result passed back to the script.", "label": "Address Book", "shortLabel": "Address Book" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code var workflowTitle = "Address Book" workflowTitle = encodeURIComponent(workflowTitle) var urlStr = "shortcuts://run-workflow?name=" + workflowTitle var url = URL.fromString(urlStr) url.call(function(resultObj){ var contactName = resultObj.name var contactPhone = resultObj.phone // PROCESS RESULTS OF WORKFLOW }, function(error){ new Alert("SCRIPT ERROR", error).show() console.error(error) }) }); action.validate = function(selection, sender){ return true }; return action; })();
UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER