如何读取引用传递的值的属性?

时间:2014-09-16 18:59:33

标签: applescript

我正在尝试编写OmniGraffle 5.3.6的脚本,其中我尝试读取layers的{​​{1}}元素,该元素已传递给函数(或处理程序,AppleScript用语)。当我运行以下内容时:

canvas

我收到以下错误:

on exportToPng(theCanvas)
    set layerCount to count of layers of theCanvas
end exportToPng

tell application "OmniGraffle Professional 5"
    set theDocument to front document
    set allCanvases to canvases of theDocument
    set theCanvas to item 1 of allCanvases
    my exportToPng(theCanvas)
end tell

但是,如果我要内联我的功能,那么一切正常:

  error "OmniGraffle Professional 5 got an error: Can’t make |layers| of
  canvas id 1 of document \"base-dependency-diagram.graffle\" into type reference."
  number -1700 from |layers| of canvas id 1 of document
  "base-dependency-diagram.graffle" to reference

我看了Passing by Reference Versus Passing by Value,但我觉得它没有帮助。它很稀疏。

1 个答案:

答案 0 :(得分:1)

您可以通过引用传递。但是,无论你通过哪里,它也必须有#34;告诉应用程序"以便应用程序可以处理传递的引用。所以你会希望你的功能像......

on exportToPng(theCanvas)
    tell application "OmniGraffle Professional 5"
      set layerCount to count of layers of theCanvas
    end tell
end exportToPng

毕竟,只有" OmniGraffle Professional 5"知道如何从theCanvas获取图层。