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

Dmi*_*kov 6 applescript

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

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

tell application "Finder"
    stub()
end tell
Run Code Online (Sandbox Code Playgroud)

Ant*_*sky 14

在一个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
Run Code Online (Sandbox Code Playgroud)