从 tell Finder 块中调用时 AppleScript 处理程序不起作用

AppleScript handler not working when called from within tell Finder block

学习使用 AppleScript 中的处理程序我 运行 遇到了问题。目前我已经调整我的应用程序以在 运行 时调用处理程序,但目前我收到一个错误:

error "Script Editor returned error -1708" number -1708

编译时没有问题。当我尝试研究解决方案时,我无法找到这在应用程序查找器下不起作用的原因。为了记忆,我记得 on run 必须在应用程序中最后声明。

代码:

on checkForRebels(tieFighter, starDestroyer)
    display dialog "dark enough" as text
end checkForRebels

on run
    tell application "Finder"
        set the starDestroyer to (choose folder with prompt "Please select the Destroyer")
        set tieFighter to items of starDestroyer
        checkForRebels(tieFighter, starDestroyer)
    end tell
end run

我尝试搜索

applescript items throw error when passing to handler

但我退回了 Apple 的 Working with Errors which doesn't answer my question. When I review Apple's documentation About Handlers 我没有看到任何披露问题的内容。

当我将脚本修改为:

on checkForRebels(tieFighter, starDestroyer)
    display dialog "dark enough" as text
end checkForRebels

on run
    tell application "Finder"
        set the starDestroyer to (choose folder with prompt "Please select the Destroyer")
        set tieFighter to items of starDestroyer
    end tell
    checkForRebels(tieFighter, starDestroyer)
end run

它可以正常工作,但为什么处理程序 checkForRebels() 在应用程序 Finder 的 tell 块中不起作用?当我调用处理程序时,我是否必须始终在应用程序之外执行它才能工作?

当您从 tell 块或其他处理程序中调用处理程序时,您需要指定 "my",否则它会在 Finder 字典中查找该命令。

my checkForRebels(tieFighter, starDestroyer)

来自 Applescript 语言指南Calling Handlers in a tell Statement

To call a handler from within a tell statement, you must use the reserved words of me or my to indicate that the handler is part of the script and not a command that should be sent to the target of the tell statement.