Applescript中的tell块中的处理程序调用错误

时间:2010-04-18 20:24:24

标签: applescript

为什么不在tell块中调用处理程序? 错误是-1708

on stub() -- method is not called in tell block
end stub

tell application "Finder"
    stub()
end tell

1 个答案:

答案 0 :(得分:13)

tell SOMETHING块中,AppleScript在SOMETHING内查找命令。在这种情况下,它正在stub内寻找application "Finder"命令;这显然不存在。要告诉AppleScript查找您定义的函数,请编写my stub(); my强制它查看当前脚本的正文而不是application "Finder"。在这种情况下,这会给你:

on stub()
    -- ...
end stub

-- ...
stub() -- Works fine
-- ...

tell application "Finder"
    -- ...
    my stub() -- With the `my`, works fine
    -- ...
end tell