JXA & OmniGraffle

Я не могу понять, как перевести следующий AppleScript в JXA (JavaScript для автоматизации под 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

Вот что я пробовал, но это не удается при выполнении последней строки с ошибкой "Ошибка обработчика AppleEvent":

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)

Кто-нибудь может помочь?

Спасибо, Аурелиен

2 ответа

Графические объекты (линии, фигуры, ...) содержатся в графической коллекции. Таким образом, вы должны изменить последнюю строку на

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

И эквивалентный, но немного более полный пример:

(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;

})();
Другие вопросы по тегам