Applescript - 如何从内部访问顶级处理函数告诉Application

时间:2018-02-05 18:55:56

标签: macos scripting applescript handler

我正在尝试编写一个打开应用程序(Slack)的自定义Apple脚本,并在继续之前运行检查以确保它已完全加载。我目前收到错误:

Slack got an error: Can’t continue processCheck. -1708

1708是错误:The script doesn’t understand the <message> message. The event was not handled.

这是我的代码:

tell application "Slack" to activate
global is_loaded
set is_loaded to false

processCheck()

on processCheck()
    tell application "System Events" to get name of every process
    if the result contains "Slack" then
        log "running"
        tell application "Slack"
            if (count of windows) > 0 then
                set window_name to name of front window
                log window_name
                #when window_name is just Slack, it should mean Slack is still loading
                if window_name is equal to "Slack" then
                    log "loading"
                    delay 0.5
                    if is_loaded is equal to false then
                        processCheck()
                    end if
                else
                    is_loaded = true
                    #if it is something else, it should mean Slack has loaded the user's default workspace
                    log "loaded"
                end if
            end if
        end tell
    else
        log "not running"
        delay 5
        processCheck()
    end if
end processCheck

我认为发生的事情是我的脚本认为我试图告诉Slack运行函数processCheck(),但实际上我只想告诉我的苹果脚本运行processCheck()

如何解决此错误?

1 个答案:

答案 0 :(得分:1)

这是一个非常常见的错误。

来自documentation

  

要从tell语句中调用处理程序,必须使用保留字of memy来指示处理程序是脚本的一部分,而不是应该使用的命令被发送到tell声明的目标。

my processCheck()