屏幕上的屏幕镜像在壁灯的控制中心?

问题描述 投票:0回答:1

OS和程序详细信息

  • MACOSMONTEREY(12.3+):这仅适用于12.3或更高,因为随着通用控制的引入,激活/停用sidecar的方法发生了一些变化(而不是在CC显示模块中,Sidecar的按钮获得了移入屏幕镜像)
  • Device
  • :M1 MacBook Pro 13英寸(2020年底)。不确定这是否重要,但认为包括以防万一会有帮助。 Application:内置和运行
  • 问题
  • 因此,我正在尝试构建一个启动/结束边缘连接的苹果本,并通过GUI脚本脚本脚本脚本控制中心(而不是系统偏好,或者包括屏幕镜像菜单栏项目)实现此目标) . 我似乎已经放下了一部分,但是实际上无法单击“屏幕镜像”按钮(或复选框,如AppleScript中的分类);它无能为力。这是我到目前为止的代码:
    Script Editor.app
  • 我尝试过的事物
我仍然是AppleScript的新鲜事物,因此我尝试在迭代中构建脚本。我首先尝试在CC中获取所有可能的复选框:

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上)。
macos applescript sidecar
1个回答
4
投票

如果您想查看我的苹果本here

。我能够在屏幕镜像下拉菜单中选择一个设备,这也可能帮助您完成所需的内容。

    溶解:通过快捷方式从iPad启动边锋,然后“通过ssh”运行脚本 我解决并记录了问题和解决方案!应该在Macos Ventura和iPad上工作,支持Apple Sidecar和快捷方式应用程序。
  1. 即将从我的github repo获取脚本:github.com/manueltdev/sidecar_via_ssh
  2. 文件也附加为readme文件!

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


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.