【问题标题】:JXA & OmniGraffleJXA 和 OmniGraffle
【发布时间】:2015-12-29 01:10:01
【问题描述】:

我不知道如何将以下 AppleScript 翻译成 JXA(Mac OS X Yosemite 下的自动化 JavaScript):

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 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)

谁能帮忙?

谢谢, 奥雷连

【问题讨论】:

    标签: javascript applescript osx-yosemite javascript-automation


    【解决方案1】:

    图形集合中包含图形对象(线条、形状等)。因此,您必须将最后一行更改为

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

    【讨论】:

      【解决方案2】:

      还有一个等价但稍微完整的例子:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-03-31
        • 1970-01-01
        • 2015-04-30
        • 2016-11-14
        • 1970-01-01
        • 2018-06-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多