UPDATE: solved and understood now, and it seems that there will soon be a new example on the website
According to the omni-automation.com website:
PlugIn actions are available to be called by other actions and external Omni Automation scripts.
This would be very useful, but is currently prevented by what looks like a bug in the selection argument passed to plugin actions.
The selection argument is typically needed by code called by both the .validate() and .perform() methods of a PlugIn.action.
When code is evaluated within a plugin, the selection argument is passed correctly both to the perform method and to the validate method.
When, however, code is called from:
- Other scripts
- The console
The validate method is still passed a well-formed Selection object,
but the perform method is only getting an undefined
value, which makes code choke on lack of access, through the selection, to canvas, view, graphics, etc âŚ
Sample test code defining an action and its validation
var _ = (function () {
var cycleTidy = new PlugIn.Action(function (selection) {
console.log("Plugin action selection argument: " + typeof selection)
this.tidyTreeLib.tidyLayout(
selection, ['Top', 'Left', 'Bottom', 'Right']
);
});
return (
cycleTidy.validate = function (selection) {
console.log("Validation fn selection argument: " + typeof selection)
return selection.canvas !== null;
},
cycleTidy
);
})();
_;
When this is called by the plugin itself, the selection argument of both methods is passed a javascript object
But if we try to call the action from an external script, or from the console, we hit a bug - the perform method is passed an undefined
value instead of the selection object, and our code quickly chokes âŚ
(Note that the validate() method does seem to be passed an object when called from the terminal or an external script, so perhaps there is hope of a fix)
OG7.4 build
OmniGraffle 7.4 test (v179.5 r291208 built Jun 29 2017)
( It looks like the same problem may be arising on iOS with OG3 test builds, but the OG3 omniJS console.log() is losing messages when script is run from a URL, so its a little harder to check )
(This is the first glitch for which I havenât found any workaround â but that could just be summer heat âŚ)