【问题标题】:Open Screen Mirroring in Control Center for Sidecar?在 Sidecar 的控制中心打开屏幕镜像?
【发布时间】:2022-07-03 18:02:39
【问题描述】:

操作系统和程序详情

  • ma​​cOS Monterey (12.3+):这仅适用于 12.3 或更高版本,因为随着 Universal Control 的引入,激活/停用 Sidecar 的方法发生了一些变化(而不是在 CC Display 模块中, Sidecar 的按钮已移至 Screen Mirroring)
  • 设备:M1 MacBook Pro 13 英寸(2020 年末)。不确定这是否重要,但认为包括在内以防万一会有所帮助。
  • 应用程序:在内置Script Editor.app 中构建和运行

问题

所以离开这个link,我正在尝试构建一个启动/结束 Sidecar 连接的 AppleScript,并通过 GUI 脚本控制中心(而不是系统偏好设置,或通过包含屏幕镜像菜单栏)来实现这一点项目)。

我似乎已经关闭了一部分,但无法实际单击屏幕镜像按钮(或复选框,因为它在 AppleScript 中归类);它什么也不做。这是我到目前为止的代码:

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

我尝试过的事情

我对 AppleScript 还是有点陌生​​,所以我尝试在迭代中构建脚本。我首先尝试通过以下方式获取 CC 中所有可能的复选框:

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

返回此列表(链接键盘和鼠标不是我正在寻找的不是 - 那是通用控制,而不是 Sidecar):

{"Wi‑Fi", "Focus", "Bluetooth", "AirDrop", "Screen Mirroring", "Link keyboard and mouse", "Airplay Audio"}

设置 Screen Mirroring 复选框不会引发错误(并且可以返回),但 click 命令不会(似乎)对此做任何事情:

set myToggle to (checkbox 1 of window "Control Center" whose title is "Screen Mirroring")
click myToggle

为了确保单击命令确实执行了某些操作,我通过以下方式使用 AirDrop 复选框进行了尝试:

set myToggle to (checkbox 1 of window "Control Center" whose title is "AirDrop")
click myToggle

这按预期工作; CC 中的 AirDrop 图标已切换(在“仅限联系人”和“关闭”之间切换)。然后我继续尝试使用上面ccCheckboxes 中返回的所有其他复选框, 屏幕镜像的所有功能都有效:所有切换(Wi-Fi、Focus、蓝牙、AirDrop)在打开和关闭之间切换,其余的(链接键盘和鼠标、Airplay 音频)打开它们的辅助窗口。我做错了什么还是这只是一个错误?

【问题讨论】:

    标签: macos applescript sidecar


    【解决方案1】:

    通过系统偏好设置的替代方法:https://gist.github.com/chatchavan/6e60982b80b96a3be155023a5afe8d30

    (在 macOS Monterrey 12.4 上测试)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-27
      • 2013-06-12
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2020-03-10
      • 2012-01-24
      • 1970-01-01
      相关资源
      最近更新 更多