【问题标题】:Apple Script Error: Can't continue clickApple 脚本错误:无法继续单击
【发布时间】:2015-08-21 08:56:26
【问题描述】:

我正在尝试打开一个消息应用程序(它没有 Apple Script Dictionary (command + shift + o)),单击文本,然后在文本框中输入内容,然后点击发送。

应用程序激活后弹出:脚本错误 - Telegram got an error: Can't continue click

结果标签:error "Telegram got an error: Can’t continue click." number -1708

P.S.,消息应用是 Telegram

苹果脚本:

tell application "Telegram"
    activate
    delay 1
    click on text "chat name"
    keystroke "some text"     
    //assuming this works because text box is the first responder when the chat opens.
    click on text "Send"
end tell

【问题讨论】:

    标签: macos automation applescript


    【解决方案1】:

    如果应用程序缺少 AppleScript 字典,则除标准命令 launchactivateopenreopenquit 之外的任何命令都会引发错误。

    解决方案是 GUI 脚本:内置应用程序 System Events 是向目标应用程序发送鼠标点击和键盘事件的桥梁。

    我根本不知道应用程序 Telegram,所以这段代码可能会失败,但它也可能是一个起点

    activate application "Telegram"
    tell application "System Events"
      tell process "Telegram"
        tell window 1
          keystroke "some text"     
          click button "Send"
        end tell
      end tell
    end tell
    

    【讨论】:

    • 有没有办法复制click on text "chat name"
    • 试试set value of text field 1 to "some text"。如果有更多文本字段,索引可能会有所不同
    • 不,我所说的聊天名称是指选择一个聊天,然后选择要输入的文本字段。喜欢 - activate -> 选择 chat name -> 选择 text field -> 输入 @987654334 @ -> 点击send 按钮。
    • 这可能是可能的,但 GUI 脚本很大程度上依赖于 UI 环境。试试 UIElementInspector 看看:developer.apple.com/library/mac/samplecode/UIElementInspector/…
    【解决方案2】:

    对于缺少 AppleScript 字典的第 3 方应用程序,您有两种选择。

    选项 1:

    使用上述系统事件对元素执行操作,例如单击按钮,将文本键入字段等。诀窍是在 Applescript 识别的语法中识别元素。除了上面提到的 UIElementInspector 可能会令人困惑并且偶尔会出错/不完整,您还可以在单​​独的 Applescript 编辑器中运行以下命令。例如,要获取 Telegram 中活动窗口(窗口 1)的所有 UI 元素:

        tell application "System Events" to tell application process "Telegram" to tell window 1
                UI elements
        end tell
    

    在 Telegram 中获取主菜单栏的所有 UI 元素:

        tell application "System Events" to tell application process "Telegram" to tell menu bar 1
                UI elements
        end tell
    

    在每种情况下,结果窗格都会显示该窗口或菜单栏中所有可用 UI 元素的逗号分隔列表。此外,Applescript 保证可以识别列出的语法。只需识别正确的元素并告诉系统事件告诉它该做什么。

    例如,如果您想在 TextEdit 中单击菜单项“格式”,请先运行以下命令:

        tell application "System Events" to tell application process "TextEdit" to tell menu bar 1
            UI elements
        end tell
    

    “结果”窗格中的结果如下:

         menu bar item "Format" of menu bar 1 of application process "TextEdit" of application "System Events"
    

    将其转换为 Applescript,运行脚本,它将单击“格式”菜单:

        tell application "TextEdit" to activate --you need TexEdit up and running to click its menu bar
    
        tell application "System Events" to click menu bar item "Format" of menu bar 1 of application process "TextEdit"
    

    对于子菜单等,您只需迭代请求子菜单的 UI 元素的过程。 GUI 脚本是迭代和经验的。

    选项2:

    下载免费的终端/命令行应用程序cliclick,它允许您单击屏幕上的任何点。按住command + shift + 4,可以用光标手动识别你要点击的屏幕坐标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-04
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 2021-05-24
      相关资源
      最近更新 更多