【问题标题】:Applescript - how to access top level handler function from inside tell ApplicationApplescript - 如何从内部访问顶级处理程序函数告诉应用程序
【发布时间】:2018-07-15 17:21:36
【问题描述】:

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

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()

如何解决这个错误?

【问题讨论】:

    标签: macos scripting applescript handler


    【解决方案1】:

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

    来自documentation

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

    my processCheck()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多