Plug-In: Script URL for Plug-In

Plug-In Interface

This plug-in will place an Omni Automation Script URL for the chosen plug-in action, on the clipboard. The generated script URL can be used in Shortcuts or other 3rd-party applications to externally trigger the execution of targeted the plug-in.

An Automated Shortcuts Workflow

Here’s an example of how to set up the script URL to execute as the result of a Shortcuts Automation triggered workflow.

shortcuts-workflow-approval

 1  Shortcuts Automation • A Shortcuts Automation workflow actions list.

 2  Open URLs Action • A single instance of the Open URLs action from the Safari collection.

 3  Script URL • The generated script URL for running the chosen installed Omni Automation plug-in is pasted into the Shortcuts action as the URL value.

 4  Script Security Dialog • The first time the script URL is executed, this security dialog will appear.

 5  Automatic Approval • Select this switch to allow the indicated script URL to execute without requiring re-approval.

The OmniFocus plug-in shown above is the Just For Today plug-in, which will extract the text contents of a webpage and place that as the value of the notes field of an existing/created task.

Script URL for Plug-In

This plug-in incorporates “follow-on menus” to present a form whose menus update automatically based upon the selection of the first menu.

To use the installed plug-in:

Return to: OmniFocus Plug-In Collection

Script URL for Plug-In
  

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.of-script-url-for-plug-in", "version": "1.1", "description": "Places a Script URL for executing the chosen plug-in, on the clipboard.", "label": "Script URL for Plug-In", "shortLabel": "URL for Plug-In", "paletteLabel": "Plug-In URL", "image": "link" }*/ (() => { const action = new PlugIn.Action(async function(selection, sender){ pluginRecords = new Array() PlugIn.all.forEach(plugin => { var pluginRecord = {} pluginRecord.id = plugin.identifier pluginRecord.author = plugin.author pluginRecord.version = plugin.version.versionString pluginRecord.description = plugin.description pluginRecord.displayName = plugin.displayName var actionRecords = [] plugin.actions.forEach(action => { var actionRecord = {} actionRecord.name = action.name actionRecord.label = action.longLabel actionRecords.push(actionRecord) }) pluginRecord.actions = actionRecords pluginRecords.push(pluginRecord) }) // console.log(JSON.stringify(pluginRecords)) pluginIDs = pluginRecords.map(item => item.id) plugInMenuIndexes = pluginIDs.map((item, index) => index) pluginMenu = new Form.Field.Option( "pluginIndex", "Plug-In ID", plugInMenuIndexes, pluginIDs, 0 ) pluginMenu.allowsNull = false pluginActionNames = pluginRecords[0].actions.map(item => item.name) pluginActionIndexes = pluginActionNames.map((item, index) => index) actionMenu = new Form.Field.Option( "actionIndex", "Action", pluginActionIndexes, pluginActionNames, 0 ) actionMenu.allowsNull = false form = new Form() form.addField(pluginMenu) form.addField(actionMenu) form.validate = function(formObject){ var pluginIndex = formObject.values["pluginIndex"] if (pluginIndex !== currentPluginIndex){ currentPluginIndex = pluginIndex form.removeField(form.fields[1]) } if (form.fields.length === 1){ var pluginActionNames = pluginRecords[pluginIndex].actions.map(item => item.name) var pluginActionIndexes = pluginActionNames.map((item, index) => index) var actionMenu = new Form.Field.Option( "actionIndex", "Action", pluginActionIndexes, pluginActionNames, 0 ) actionMenu.allowsNull = false form.addField(actionMenu) } return true } currentPluginIndex = 0 formPrompt = "Choose a plug-in:" buttonTitle = "Continue" formObject = await form.show(formPrompt, buttonTitle) pluginIndex = formObject.values["pluginIndex"] pluginRecord = pluginRecords[pluginIndex] pluginID = pluginRecord.id actionIndex = formObject.values["actionIndex"] actionName = pluginRecord.actions[actionIndex].name codeString = `PlugIn.find("${pluginID}").action("${actionName}").perform()` scriptURLString = "omnifocus://localhost/omnijs-run?script=" + encodeURIComponent(codeString) Pasteboard.general.string = scriptURLString new Alert("Script URL Created", "The script URL for the chosen plug-in is on the clipboard.").show() }); action.validate = function(selection, sender){return true}; return action; })();