Is it possible to activate a script inside OF via URL on macOS, passing arguments to it?
There is a workaround available:
Add an INBOX item in a specific format via omnifocus:///add
Make the script running all the time, polling INBOX, and reacting to it, or maybe activate it via AppleScript
But this is a very roundabout way to achieve the result, and it creates useless trasient INBOX items that, given a bad timing, may also get synced to other devices.
Installed plug-ins can be called externally. For example, here is the function for calling a specific action by name:
function performPlugInAction(PlugInID, actionName){
var aPlugin = PlugIn.find(PlugInID)
if (aPlugin == null){throw new Error("Plugin is not installed.")}
var actionNames = aPlugin.actions.map(function(action){
return action.name
})
if(actionNames.indexOf(actionName) == -1){
throw new Error("Action “" + actionName + "” is not in the PlugIn.")
} else {
if(aPlugin.action(actionName).validate()){
aPlugin.action(actionName).perform()
} else {
throw new Error("The action “" + actionName + "” is not valid to run.")
}
}
}
performPlugInAction("com.omni-automation.plugin-id", "nameOfAction")
This function and call can be encoded into a script URL that can be called from other apps or placed in a webpage:
IMPORTANT NOTE:
If a plug-in action is designed to process the currently selected items in the app, then it must be adapted to check for the passed selection to be “undefined” and generate the selection object itself. The following example is for OmniOutliner:
var action = new PlugIn.Action(function(selection){
// if called externally (from script) generate selection array
if (typeof selection == 'undefined'){
// convert nodes into items
nodes = document.editors[0].selectedNodes
selectedItems = nodes.map((node) => {return node.object})
} else {
selectedItems = selection.items
}
// action code …
});
I need to confess that I have tried this numerous times with my placeholder template script and it always fails. As in, OmniFocus crashes. I’m guessing it has something to do with opening the FilePicker.
Is it not possible to simply pass the name of the script? Something like this: