Applescript打开后点击系统菜单栏中的项目



我可以用这段代码打开蓝牙下拉菜单项,但我不知道如何实际单击菜单中的任何项。

tell application "System Events" to tell process "ControlCenter"
click menu bar item "Bluetooth" of menu bar 1
end tell

在打开的蓝牙菜单中点击某个东西的命令是什么?

下面的AppleScript代码应该完成你想要实现的目标。只需替换"Mac Pro">代码的一部分,其中包含要单击的项的名称。

tell application "System Events" to tell process "ControlCenter"
click menu bar item "Bluetooth" of menu bar 1
repeat until exists of checkbox 1 of scroll area 1 of window 1
delay 0.1
end repeat
click checkbox "Mac Pro" of scroll area 1 of window 1
key code 53 -- Press escape key
end tell

AppleScriptCode将返回复选框的名称,以便您可以轻松地知道要在第一个代码中使用的选项。

tell application "System Events" to tell process "ControlCenter"
click menu bar item "Bluetooth" of menu bar 1
repeat until exists of checkbox 1 of scroll area 1 of window 1
delay 0.1
end repeat
set checkBoxNames to name of checkboxes of scroll area 1 of window 1
end tell

最新更新