使用Apple Script单击按钮

时间:2018-04-11 13:55:13

标签: macos applescript

我想从Apple脚本向UI应用程序添加一些细节。 但我无法从脚本中单击UI中的“新建”按钮。

tell application "System Events" to tell process "Microsoft Remote Desktop"
    --click button 1 of group 1 of toolbar 1 of window 1
    click button "New" of group 1 of toolbar 1 of window 1
end tell

mstsc

辅助功能检查员

enter image description here

1 个答案:

答案 0 :(得分:1)

你不能使用"新"对于按钮 name,因为name的{​​{1}} 属性button 1 of group 1 of toolbar 1 of window 1 of application process "Microsoft Remote Desktop"

但是,missing value 属性description,因此以下示例 AppleScript 代码适用于我:

New
  • 请注意,可能需要针对您的系统和/或其他activate application "Microsoft Remote Desktop" delay 1 tell application "System Events" to tell application process "Microsoft Remote Desktop" click (every button of group 1 of toolbar 1 of window 1 whose description is "New") end tell 命令调整delay 命令 可能需要也可能不需要。根据需要调整和/或添加/删除delay 命令

如果 Microsoft远程桌面已在运行,您可以使用以下示例代码行来获取delay属性只打开主窗口:

button 1 of group 1 of toolbar 1 of window 1

注意: 示例 AppleScript 代码就是这样,并且不使用任何错误处理并且仅用于显示完成任务的多种方法之一。用户有责任根据需要添加/使用适当的错误处理