You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在macOS 13 (Ventura)用AppleScript旋转外接显示器

macOS Ventura 外接显示器定向旋转/恢复的AppleScript解决方案

以下是针对Ventura系统改动优化的AppleScript脚本,可实现指定外接显示器的90度旋转/原状恢复,同时解决设置项名称变更、特定显示器选择、确认弹窗自动处理三个问题:

-- 配置参数:替换为你的目标外接显示器名称(可在「显示器设置」顶部下拉菜单查看)
set targetDisplay to "DELL U2720QM"
-- 旋转方向:可选值 "90°"、"180°"、"270°"、"标准"(恢复原状用"标准")
set rotationDirection to "90°"

-- 直接定位并打开显示器设置面板
tell application "System Settings"
    activate
    reveal pane id "com.apple.Displays-Settings.extension"
end tell

-- 等待设置面板加载完成
delay 1

tell application "System Events"
    tell process "System Settings"
        -- 切换到目标显示器的设置界面
        set displayMenu to pop up button 1 of group 1 of group 1 of window "显示器"
        click displayMenu
        click menu item targetDisplay of menu of displayMenu
        
        -- 执行旋转操作
        click pop up button 2 of group 1 of group 1 of window "显示器"
        click menu item rotationDirection of menu of pop up button 2 of group 1 of group 1 of window "显示器"
        
        -- 自动处理旋转确认弹窗
        try
            click button "确认" of sheet 1 of window "显示器"
        end try
    end tell
end tell

-- 自动关闭系统设置(可根据需求删除此段保留设置窗口)
quit application "System Settings"

关键问题解决说明

  • 适配Ventura设置项变更:通过面板ID直接定位显示器设置模块,避开UI名称变动影响;同时调整了控件层级定位,匹配Ventura的设置界面结构。
  • 选中特定外接显示器:通过targetDisplay变量指定目标显示器名称,脚本自动切换到对应设备的设置页,无需手动选择。
  • 自动处理确认弹窗:用try...end try块捕获并触发确认按钮,即使系统弹出旋转验证提示也能自动完成操作。

转为快捷指令步骤

  1. 打开「快捷指令」应用,点击「创建快捷指令」。
  2. 搜索并添加「运行AppleScript」动作,将上述脚本粘贴到输入框。
  3. 修改targetDisplay为你的显示器名称,按需调整rotationDirection参数。
  4. 保存快捷指令,可设置为菜单栏快捷方式或绑定键盘快捷键触发。

注意事项

  • 首次运行前需给「快捷指令」或「脚本编辑器」授予「辅助功能」权限(路径:系统设置→隐私与安全性→辅助功能)。
  • 若脚本因显示器型号差异失效,可通过「脚本编辑器」的「显示→显示检查器」查看UI元素的准确路径进行微调。

内容的提问来源于stack exchange,提问作者Paul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 01:17:20