Apple Script Error: Can't continue click
Apple Script Error: Can't continue click
我正在尝试打开消息传递应用程序(它没有 Apple Script 词典(command + shift + o)),单击文本,在文本框中键入内容,然后单击发送。
Pop up: Script Error - Telegram got an error: Can't continue click
after the application becomes active.
Result Tab: error "Telegram got an error: Can’t continue click." number -1708
P.S., 消息应用程序是 Telegram.
Apple Script:
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
如果应用程序缺少 AppleScript 字典,除标准命令 launch
、activate
、open
、reopen
和 quit
之外的任何命令都会抛出异常一个错误。
解决方案是 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
对于缺少 AppleScript 词典的第 3 方应用程序,您有两种选择。
选项 1:
如上所述使用系统事件对元素执行操作,例如单击按钮,将文本键入字段等。诀窍是识别 Applescript 可识别的语法元素。除了上面提到的 UIElementInspector,这可能会造成混淆,偶尔 wrong/incomplete,您还可以 运行 在单独的 Applescript 编辑器中使用以下命令。例如,要获取 Telegram 中活动 window (window 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
在每种情况下,结果窗格将显示一个逗号分隔的列表,其中包含该 window 或菜单栏中所有可用的 UI 元素。此外,Applescript 保证可以识别列出的语法。只需识别正确的元素并告诉系统事件告诉它做什么。
例如,如果要单击菜单项 "Format" 首先在 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,运行 脚本,它将单击 "Format" 菜单:
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:
下载免费的 Terminal/Command Line 应用程序 cliclick,它允许您单击屏幕上的任意点。你要点击的屏幕坐标可以通过按住command + shift + 4用你的光标手动识别。
我正在尝试打开消息传递应用程序(它没有 Apple Script 词典(command + shift + o)),单击文本,在文本框中键入内容,然后单击发送。
Pop up: Script Error -
Telegram got an error: Can't continue click
after the application becomes active.Result Tab:
error "Telegram got an error: Can’t continue click." number -1708
P.S., 消息应用程序是 Telegram.
Apple Script:
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
如果应用程序缺少 AppleScript 字典,除标准命令 launch
、activate
、open
、reopen
和 quit
之外的任何命令都会抛出异常一个错误。
解决方案是 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
对于缺少 AppleScript 词典的第 3 方应用程序,您有两种选择。
选项 1:
如上所述使用系统事件对元素执行操作,例如单击按钮,将文本键入字段等。诀窍是识别 Applescript 可识别的语法元素。除了上面提到的 UIElementInspector,这可能会造成混淆,偶尔 wrong/incomplete,您还可以 运行 在单独的 Applescript 编辑器中使用以下命令。例如,要获取 Telegram 中活动 window (window 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
在每种情况下,结果窗格将显示一个逗号分隔的列表,其中包含该 window 或菜单栏中所有可用的 UI 元素。此外,Applescript 保证可以识别列出的语法。只需识别正确的元素并告诉系统事件告诉它做什么。
例如,如果要单击菜单项 "Format" 首先在 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,运行 脚本,它将单击 "Format" 菜单:
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:
下载免费的 Terminal/Command Line 应用程序 cliclick,它允许您单击屏幕上的任意点。你要点击的屏幕坐标可以通过按住command + shift + 4用你的光标手动识别。