Reliable ? Informative ? The quality of omni-automation examples

@Sal argues in another thread that new omni-automation examples need to go on using bear-trap and deprecated idioms like var and new Array() in JS for ‘uniformity’ with earlier examples supplied for OmniGraffle and OmniOutliner.

Presumably this means uniform quality rather than consistently leading customers into time-wasting and redundant complexity ?

Lets look at

The first example of var was discussed in another thread.



  • Shows a strangely complicated way of doing something simple
  • shows no result when it is pasted and entered
  • pollutes the global name-space
  • Cat-walks several deprecated idioms which increase complexity and risk without reward
  • fails to show much simpler idioms using built-in Array methods like .map, .flatMap and .flat()
var gs = new Array()
    gs = gs.concat(

Any one of these much simpler forms could have been directly pasted and (unlike the code above) actually shown a result:

  • canvases.flatMap(canvas =>

or equivalently:

  • =>

or (if some mysterious complexity is really insisted on):

  • [].concat( =>

But apparently the author of the omni-automation examples has not looked at the standard built-in Array methods …


Do things get better ?

Not really. Let’s look further down the page to the first announcement that "here’s how to XYZ:"

And here’s how to reorder graphics in a specified layer.
Order Graphics in Specified Layer

var cnvs =[0].selection.canvas
var layerNames ={
var targetName = "Cities"
if (layerNames.includes(targetName)){
    var targetLayer = cnvs.layers.filter(function(layer){
        if ( === targetName){return layer}
} else {
    throw new Error("Layer not found.")
targetLayer = targetLayer[0]
var names ={
    graphic = cnvs.graphicWithName(name)

We’re used to the dense and exuberant cat-walking of deprecated practice, so let’s ignore that for the moment.

It get’s weirdly complex as soon as it "shows us how to" (tm) find a particular layer by its name.

var targetName = "Cities"
if (layerNames.includes(targetName)){
    var targetLayer = cnvs.layers.filter(function(layer){
        if ( === targetName){return layer}
} else {
    throw new Error("Layer not found.")

The only explanation for this strange complexity that comes to mind is that the author may not be familiar with the the very basic built-in Array.findIndex

Assuming that the name canvas has already been given to:[0].selection.canvas

We could have skipped all that and simply written the elementary:

const layerIndex = canvas.layers.findIndex(
    layer => === "Cities"

If no matching layer is found we get the special index -1, and we can report that the layer was missing.

Otherwise, we can now directly refer to the layer we want:


I’m not sure that the muddle that was shown instead of this was very respectful of customer time, or very curious about learning the basics and passing them on.

But we’re not yet out of the woods with this example:

  1. it doesn’t work,
  2. it’s completely muddled (and misleading) about how Array.filter actually works, and
  3. it’s purpose is more than a little unclear.
    • We are sorting by name ? Most graphics don’t have a name by default …
    • We are sorting by graphic type ? Well … most shapes will share a type name or constructor name with many peers …
    • We are sorting by city names in the text of the shapes ? Then the code is sorting by the wrong shape property …

Try it.