Script Editor.app
set deviceName to "iPad"
set sysVer to system version of (system info) as real
tell application "System Events"
tell its application process "ControlCenter"
activate
-- Click the Control Center menu and give it time to draw
click menu bar item "Control Center" of menu bar 1
delay 1
if sysVer ≥ 12.3 then
-- Get the Screen Mirroring "checkbox" and click it
set screenMirroringToggle to (checkbox 1 of window "Control Center" whose title is "Screen Mirroring")
click screenMirroringToggle
-- Do stuff that gets the iPad button to start/end Sidecar
else
-- Do stuff for other versions of macOS Monterey or Big Sur
end if
end tell
end tell
返回此列表(link键盘和鼠标是我要寻找的东西 - 那就是通用控制,而不是壁板):
if sysVer ≥ 12.3 then
-- Get all checkboxes in the Control Center menu
set ccCheckboxes to title of (every checkbox of window "Control Center")
return ccCheckboxes
end if
设置屏幕镜像复选框不会引发任何错误(可以返回),但是点击命令没有(似乎是)对此做任何事情:
{"Wi‑Fi", "Focus", "Bluetooth", "AirDrop", "Screen Mirroring", "Link keyboard and mouse", "Airplay Audio"}
为了确保单击命令实际上做某事,我尝试使用Airdrop复选框尝试:
set myToggle to (checkbox 1 of window "Control Center" whose title is "Screen Mirroring")
click myToggle
这是按预期的; CC中的空调图标已切换(仅在“仅接触”和“关闭”之间切换)。然后,我继续尝试使用上面set myToggle to (checkbox 1 of window "Control Center" whose title is "AirDrop")
click myToggle
中的其他所有复选框,所有其他复选框,所有内容但所有屏幕镜像都可以:所有toggles(Wi-fi,focus,蓝牙,airdrop)在开机和关闭之间开关,其余(链接键盘和鼠标,AirPlay Audio)打开其辅助窗口。我是在做错什么还是只是一个错误?
Edit:Macos Ventura(13.0+)
对于将来偶然发现的任何人。 像Gui脚本一样的样子在此版本上比在蒙特雷上更为破坏。大多数GUI项目都将其名称从
ccCheckboxes
属性转移到了他们的
title
,因此您必须做这样的事情:
description
,我建议您在Automator中创建一个工作流程,并使用watch me do do记录您的点击并导入该快捷方式,然后使用CLI命令
set controlCenterMBI to (menu bar items of menu bar 1 whose description is "Control Center")
运行该快捷方式。
Edit:Ventura的解决方案13.0.1 因此,在文图拉(Ventura)上看起来很难。正如您所说,标题现在正在描述中,不幸的是,我发现“控制中心”本身在Menubar上只是正确的。控制中心下拉窗口中的所有项目至少从我能告诉的至少没有名称,标题和描述。因此,这基本上是反复试验,直到我找到正确的对象。我注意到的其他事情与蒙特雷不同:
屏幕镜像现在是一个按钮而不是复选框。 单击事件的执行操作2现在不起作用,它是“动作1”
shortcuts run $SHORTCUT_NAME
蒙特雷 我找到了一个在
12.0.1上对我有用的解决方案,不幸的是,我被锁定在此版本上,无法更新以测试更新版本,因此它可能对您不起作用,但值得一试。 即将替换“ click”用“执行动作2”替换。这很奇怪,但起作用(在12.0.1上)。
Maybe脆弱但在红杉15.2
上工作
-- Get the Screen Mirroring "checkbox" and click it
set screenMirroringToggle to (checkbox 1 of window "Control Center" whose title is "Screen Mirroring")
perform action 2 of screenMirroringToggle