applescript - Applescript:单击特定的菜单栏项
问题描述
我为调用的应用程序制作了一个applescript。但我有一个例外的问题:(
抱歉,但是“您需要至少 10 个声望才能发布图片。”
- https://i.ibb.co/ZMgZ5Tb/Screen-Shot-2019-04-02-at-10-22-29.png
- https://i.ibb.co/6sGyNjx/Screen-Shot-2019-04-02-at-10-22-41.png
我的问题在哪里?
tell application "System Events" to tell process "EndpointConnect"
tell menu bar item 1 of menu bar 2
click
click menu item "Disconnect" of menu 1
end tell
end tell
实际结果是:
error "System Events got an error: Can’t get menu 1 of menu bar item 1 of menu bar 2 of process \"EndpointConnect\". Invalid index." number -1719 from menu 1 of menu bar item 1 of menu bar 2 of process "EndpointConnect"
解决方案
就目前而言,脚本click
在(尚)不存在的对象上执行 a 。基本上,您需要delay
在两个click
命令之间使用一个来给系统时间来实例化菜单及其项目。
这是我无法为您测试的编辑,但我希望能奏效:
tell application "System Events" to tell ¬
process "EndpointConnect" to tell ¬
menu bar 2 to tell ¬
menu bar item 1
if not (exists) then return null
click
tell (a reference to menu item "Disconnect" of menu 1)
repeat until it exists
delay 0.5
end repeat
click
end tell
end tell
但是,由于某些未知原因,您可能会在菜单出现和单击菜单项之间出现令人讨厌的 5 秒延迟。它是众所周知的/记录在案的,经常被抱怨,并且是一个多年未解决的问题,而且可能永远不会解决。
推荐阅读
- python - SublimeText 在 virtualenv 中使用 pyflakes 对 Python3 进行 linting
- javascript - onPress 按钮在按下时不起作用
- angular - 如何在 Angular 6 中从鼠标事件中插入 CSS 效果?
- javascript - 为数据表指定 JSON 的子参数
- vba - VBA RC 选择另一行
- javascript - 如何在 ReactJS 中创建动态表?
- android - 如何检测 Cordova android 应用程序中的环境?
- r - 在 R 中为 msts() 对象设置滑动窗口
- javascript - Chart.js - 具有线性笛卡尔(数字)X 轴的条形图?
- rollupjs - Svelte CSS 的奇怪行为