我为调用的应用程序制作一个苹果脚本。但是我对例外有问题:(
抱歉,但是"您至少需要 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
。 基本上,您需要在两个click
命令之间delay
,以便系统有时间实例化菜单及其项。
这是我无法为您测试的编辑,但我希望会起作用:
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 秒延迟。 它是众所周知的/有记录的,经常被抱怨,并且是一个长达数年的问题,尚未解决,而且可能永远不会解决。