Q: Bug ? does the connect() command fail in JavaScript for Automation?

I may be missing something, but it looks as if the connect command (which works in AppleScript) is broken in JavaScript for Automation.

Is there a syntax for calling it which eludes me ?

In AS we can write:

tell application "OmniGraffle" to tell front canvas of front document
    connect shape id 1182 to shape id 1183 with properties {line type: straight}
end tell

but in JavaScript for Automation, all analogous permutations of shape reference and method location seem to lead ineluctably to an error message – ‘Can’t convert types’

Bug ? or some oversight my part ?

So far I have tried reasonably exhaustive variations of

og.connect(shp, {to:child});


  • og might be a reference to the Application or Canvas, and
  • shp, child might be otherwise fully functional references to shapes (returning true for .allowsConnections()) obtained using .byId(), byName(), array index etc etc …

We looked into this, and really have no idea either. Here are some of the things we tried:

// With a document open with two shapes
var app = Application(“OmniGraffle”)
var doc = app.documents.at(0)
var canvas = doc.canvases.at(0)
var shape0 = canvas.graphics.at(0)
var shape1 = canvas.graphics.at(1)

// app.connect(shape0, {to:shape1}) // Can’t convert types
// doc.connect(shape0, {to:shape1}) // Parameter is missing
// doc.connect(shape0, {“to”:shape1}) // Parameter is missing
// canvas.connect(shape0, {to:shape1}) // Parameter is missing
// canvas.connect(shape0, {“to”:shape1}) // Parameter is missing
// shape0.connect({to:shape1}) // Can’t convert types
// shape0.connect({“to”:shape1}) // Can’t convert types

// app.connect(shape0, shape1) // Parameter is missing
// doc.connect(shape0, shape1) // Parameter is missing
// canvas.connect(shape0, shape1) // Parameter is missing
// shape0.connect(shape1) // // Parameter is missing

In general, if something works in AppleScript and not in JXA then it’s probably an issue that Apple needs to address.

In general, if something works in AppleScript and not in JXA then it’s probably an issue that Apple needs to address.

The only thing I wondered about, in that context, is an anomaly with the line type enum, which is apparent (though not fatal) in AppleScript as well as in JavaScript.

There are two things which don’t look quite right with line types in AppleScript either:

  • An anomalous name of the enum - should be line type rather than OGLT

  • Anomalous behaviour, even in AS:

If we create shapes with connect in AppleScript, and omit the with properties clause, to use the template defaults, the line types produced with the Hierarchical template don’t seem to respect the template default, and some of them are curves with unexpected and oddly placed (distorting) mid points. (See image below).

(The template default is straight lines).

I wonder if there is a marginal non-compliance in the .sdef there which produces relatively minor bugs in AS, but trips a bigger problem in JS, which has slightly different type mappings.

CORRECTION - in OG5 and OG6 connect picks up, by default, the current line tool settings rather than the current template values.