【发布时间】:2022-01-16 00:10:13
【问题描述】:
我想编写一个简单的脚本来将我的 MacBook 连接到客厅的蓝牙扬声器,但我不知道最后的点击。
-- Turn Bluetooth on
tell application "System Preferences"
activate
reveal pane "com.apple.preferences.Bluetooth"
end tell
delay 1
tell application "System Events"
tell process "System Preferences"
if button "Turn Bluetooth On" of window "Bluetooth" exists then
click button "Turn Bluetooth On" of window "Bluetooth"
end if
end tell
end tell
-- Connect Living Room speakers
tell application "System Events"
tell process "ControlCenter"
set BluetoothButton to menu bar item "Bluetooth" of menu bar 1
click BluetoothButton --This works and makes the dialog pop up
delay 3
set TheCheckbox to button "Living Room" of scroll area 1 of window "Control Centre"
if TheCheckbox exists then return "Yay"
if value of TheCheckbox is 0 then click TheCheckbox
end tell
end tell
-- This is how to do it through the System Preferences
-- But this doesn't work because there's no way to double click the device in the bluetooth menu
(*set thePathPref to (path to library folder from system domain as text) & "PreferencePanes:"
tell application "System Preferences"
activate
reveal pane "com.apple.preferences.Bluetooth"
end tell
delay 1
tell application "System Events"
tell process "System Preferences"
if button "Turn Bluetooth On" of window "Bluetooth" exists then
click button "Turn Bluetooth On" of window "Bluetooth"
end if
delay 1
set LivingRoomButton to UI element "Living Room" of row 3 of table 1 of scroll area 1 of window "Bluetooth" of application process "System Preferences" of application "System Events"
--if LivingRoomButton exists then
click LivingRoomButton -- Needs to be a double click but that's impossible
--end if
end tell
end tell
*)
如果我
return every UI element of window "Control Centre"
我返回 {},这让我认为窗口“控制中心”不是寻找按钮的正确位置,但使用名为 UI 浏览器的应用程序,这绝对是它所在的位置。所以我不知道该怎么办。
就目前而言,我收到错误“系统事件出错:无法获取进程“控制中心”的窗口“控制中心”的滚动区域 1。索引无效。”就行了
set TheCheckbox to button "Living Room" of scroll area 1 of window "Control Centre"
【问题讨论】:
标签: macos bluetooth applescript macos-monterey