0

I can't figure out how to translate the following AppleScript into JXA (JavaScript for Automation under Mac OS X Yosemite) :

tell application id "com.omnigroup.OmniGraffle6"
    tell canvas of front window
        make new line at end of graphics with properties {point list:L, draws shadow:false}
    end tell
end tell

Here is what I've tried but this fails while executing the last line with error "AppleEvent handler failed" :

app = Application('OmniGraffle')

pt1 = app.Point({x:1,y:2})
pt2 = app.Point({x:1,y:2})

L = []
L.push(pt1)
L.push(pt2)

line = app.Line({pointList:L})

app.documents[0].canvases[0].lines.push(line)

Can anyone help ?

Thanks, Aurelien

foo
  • 3,171
  • 17
  • 18

2 Answers2

1

Graphical objects (lines, shapes, ...) are contained in the graphics collection. Thus, you have to change the last line to

app.documents[0].canvases[0].graphics.push(line)
Holger
  • 1,648
  • 1
  • 16
  • 26
0

And an equivalent but slightly fuller example:

(function () {
    'use strict';

    var og = Application("OmniGraffle"),
        ds = og.documents,
        d = ds.length ? ds[0] : null,
        cnvs = d ? d.canvases : [],
        cnv = cnvs.length ? cnvs[0] : null,
        gs = cnv ? cnv.graphics : null;

    return gs ? (
        gs.push(
            og.Line({
                pointList: [[72, 216], [216, 72]],
                drawsShadow: true,
                thickness: 3,
                lineType: 'orthogonal',
                strokeColor: [1.0, 0.0, 0.0],
                headType: "FilledArrow"
            })
        )
    ) : null;

})();
houthakker
  • 688
  • 5
  • 13