Applescript 如何读取通过引用传递的值的属性?
我正在尝试编写OmniGraffle 5.3.6脚本,其中我尝试读取已传递给函数(用AppleScript的说法是处理程序)的Applescript 如何读取通过引用传递的值的属性?,applescript,Applescript,我正在尝试编写OmniGraffle 5.3.6脚本,其中我尝试读取已传递给函数(用AppleScript的说法是处理程序)的画布的层元素。当我运行以下命令时: on exportToPng(theCanvas) set layerCount to count of layers of theCanvas end exportToPng tell application "OmniGraffle Professional 5" set theDocument to front
画布的层元素。当我运行以下命令时:
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
但是,如果我要内联函数,那么一切都可以正常工作:
tell application "OmniGraffle Professional 5"
set theDocument to front document
set allCanvases to canvases of theDocument
set theCanvas to item 1 of allCanvases
set layerCount to count of layers of theCanvas
end tell
我读了,但我觉得没有帮助。它非常稀疏。您可以通过引用传递。然而,无论您传递到哪里,它都必须具有“告诉应用程序”,以便应用程序能够处理传递的引用。所以你需要这样的函数
on exportToPng(theCanvas)
tell application "OmniGraffle Professional 5"
set layerCount to count of layers of theCanvas
end tell
end exportToPng
毕竟,只有“OmniGraffle Professional 5”知道如何从Canvas获取图层