Tools

A great scripting implementation would be unusable without the tools to create the scripts, actions, libraries, and plugins integrated into Omni suite of applications for macOS and iOS. That is why every Omni application has a built-in script console in which you can develop, test, and execute your Omni Automation JavaScript scripts.

For example, the following animation shows use of the console in OmniGraffle for macOS:

Console Functions

In addition to providing a means for running Omni Automation scripts, an Omni application’s console window allows scripts to “log” debugging, warning, or error information where it can be viewed in the system console or in the console output area. A single instance of the Console class is available to scripts as the console global variable.

Here are the functions supported by the Console:

A simple logging of a text string:

console-00

An example using the (optional) “additional” parameter to include the shape of the item being processed in the log statement:

console-01 console-02

Using the (optional) “additional” parameter to include unique identifying information about the object causing the error:

console-03

An informational example that creates and displays an informational data dictionary for each processed object:

console-04

Posting a warning about graphic names containing spaces:

console-05

Placing the console.clear() function at the start of the script will remove previous messaging from the console window and only display the results of the current script:

console-06

Graphic Summary

Here’s an example of using console logging to review the status of the graphics in the current canvas. Run the script with the OmniGraffle console window open to view the results.

Note the use of JavaScript Ternary operators in lines 8 and 10:

console.clear() graphics = document.windows[0].selection.canvas.graphics graphics.forEach(function(graphic, index){ obj = new Object() obj.layerName = graphic.layer.name obj.name = graphic.name obj.id = graphic.id obj.type = graphic instanceof Line ? "Line" : graphic.shape if (obj.type != "Line"){ obj.image = graphic.image instanceof ImageReference ? true : false } else {obj.image = false} obj.locked = graphic.locked console.log("Graphic " + String(index),JSON.stringify(obj)) })
omnigraffle://localhost/omnijs-run?script=console%2Eclear%28%29%0Agraphics%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%2Egraphics%0Agraphics%2EforEach%28function%28graphic%2C%20index%29%7B%0A%09obj%20%3D%20new%20Object%28%29%0A%09obj%2ElayerName%20%3D%20graphic%2Elayer%2Ename%0A%09obj%2Ename%20%3D%20graphic%2Ename%0A%09obj%2Eid%20%3D%20graphic%2Eid%0A%09obj%2Etype%20%3D%20graphic%20instanceof%20Line%20%3F%20%22Line%22%20%3A%20graphic%2Eshape%0A%09if%20%28obj%2Etype%20%21%3D%20%22Line%22%29%7B%0A%09%09obj%2Eimage%20%3D%20graphic%2Eimage%20instanceof%20ImageReference%20%3F%20true%20%3A%20false%0A%09%7D%20else%20%7Bobj%2Eimage%20%3D%20false%7D%0A%09obj%2Elocked%20%3D%20graphic%2Elocked%0A%09console%2Elog%28%22Graphic%20%22%20%2B%20String%28index%29%2CJSON%2Estringify%28obj%29%29%0A%7D%29
console-076

“Pre-Flight” Documents

Here’s an example of using the console to Pre-flight a document prior to saving, printing, or processing. If installed as an action, the results will log to the application’s console window when the action is selected from the Automation menu.

This example script checks for graphics that are unnamed or are set to not print. You can edit the script to check for the document or graphic properties you require.

console.clear() var cnvs = document.windows[0].selection.canvas var cnvsName = cnvs.name cnvs.graphics.forEach(function(graphic, index){ obj = new Object() obj.canvasName = cnvsName obj.layerName = graphic.layer.name obj.name = graphic.name obj.id = graphic.id obj.type = graphic instanceof Line ? "Line" : graphic.shape if (obj.type != "Line"){ obj.image = graphic.image instanceof ImageReference ? true : false } else { obj.image = false } obj.locked = graphic.locked obj.prints = graphic.layer.prints objStr = JSON.stringify(obj) if (obj.prints === false){ console.warn("Non-Printing Graphic " + String(index),objStr) } else if (obj.name === null){ console.warn("Unnamed Graphic " + String(index),objStr) } else { console.info("Graphic " + String(index),objStr) } })
omnigraffle://localhost/omnijs-run?script=console%2Eclear%28%29%0Avar%20cnvs%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0Avar%20cnvsName%20%3D%20cnvs%2Ename%0Acnvs%2Egraphics%2EforEach%28function%28graphic%2C%20index%29%7B%0A%09obj%20%3D%20new%20Object%28%29%0A%09obj%2EcanvasName%20%3D%20cnvsName%0A%09obj%2ElayerName%20%3D%20graphic%2Elayer%2Ename%0A%09obj%2Ename%20%3D%20graphic%2Ename%0A%09obj%2Eid%20%3D%20graphic%2Eid%0A%09obj%2Etype%20%3D%20graphic%20instanceof%20Line%20%3F%20%22Line%22%20%3A%20graphic%2Eshape%0A%09if%20%28obj%2Etype%20%21%3D%20%22Line%22%29%7B%0A%09%09obj%2Eimage%20%3D%20graphic%2Eimage%20instanceof%20ImageReference%20%3F%20true%20%3A%20false%0A%09%7D%20else%20%7B%0A%09%09obj%2Eimage%20%3D%20false%0A%09%7D%0A%09obj%2Elocked%20%3D%20graphic%2Elocked%0A%09obj%2Eprints%20%3D%20graphic%2Elayer%2Eprints%0A%09if%20%28obj%2Eprints%20%3D%3D%3D%20false%29%7B%0A%09%09console%2Ewarn%28%22Non-Printing%20Graphic%20%22%20%2B%20String%28index%29%2CJSON%2Estringify%28obj%29%29%0A%09%7D%20else%20if%20%28obj%2Ename%20%3D%3D%3D%20null%29%7B%0A%09%09console%2Ewarn%28%22Unnamed%20Graphic%20%22%20%2B%20String%28index%29%2CJSON%2Estringify%28obj%29%29%0A%09%7D%20else%20%7B%0A%09%09console%2Einfo%28%22Graphic%20%22%20%2B%20String%28index%29%2CJSON%2Estringify%28obj%29%29%0A%09%7D%0A%7D%29

Action Template Generators

When it comes to creating and adding Omni Automation actions to your Omni applications, the Action Template Generators are your best friend. They are webpage forms for quickly generating automation action documents for OmniGraffle and OmniOutliner.

Just fill in the action metadata information, choose the action input, and then TAP|CLICK the Show Template button!

Web Console

A powerful feature of Omni Automation scripting is its ability to integrate with applications and webpages through the use of specialized URLs. To make it easier for you to compose, execute, and integrate your scripts in web-based environments, like iOS, this website provides a web console that you can access from both your iOS and macOS devices.

Here’s the same example script as shown in the iOS console video above, but using the web-console:

The “Copy as JavaScript” Command

Here’s a fantastic way to quickly learn how to create objects and adjust the values of their properties: just ask Omni!

While an object(s) is selected, choose “Copy as JavaScript” from the Edit menu (macOS). The Omni Automation script for creating the object will be placed on the clipboard. Paste into the application’s Console, a Web Console, or a text editor to view the step-by-step procedure for re-creating the object. Very instructive!

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