MacOS Sequoia下如何用AppleScript设置Mission Control鼠标中键快捷键?
解决MacOS Sequoia 15.1/15.2中鼠标中键打开调度中心的设置问题
我习惯用鼠标中键(Mouse 3)打开MacOS调度中心,但在Sequoia 15.1和15.2版本里,“桌面与程序坞>调度中心>快捷键”中的鼠标快捷键设置无法保存,每次开机都会恢复默认值。之前尝试用default write命令解决,在Stack Overflow提问后没得到有效答复,现在想通过完整AppleScript实现该设置。目前仅能通过AppleScript打开快捷键设置窗口,代码如下:
set paneID to "com.apple.Desktop-Settings.extension" tell application "System Settings" activate delay 0.7 set the current pane to pane id paneID delay 0.7 reveal anchor "Shortcuts" of pane id paneID delay 0.7 end tell
完整AppleScript解决方案
要修改鼠标快捷键的弹出菜单,需要结合System Events模拟UI操作,具体代码如下:
set paneID to "com.apple.Desktop-Settings.extension" -- 打开调度中心快捷键设置页面 tell application "System Settings" activate delay 0.7 set the current pane to pane id paneID delay 0.7 reveal anchor "Shortcuts" of pane id paneID delay 1 -- 延长等待时间确保UI加载完成 end tell -- 模拟UI操作修改鼠标快捷键 tell application "System Events" tell application process "System Settings" -- 定位到调度中心的鼠标快捷键弹出按钮(第二个弹出菜单) set shortcutPopup to pop up button 2 of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of window "桌面与程序坞" click shortcutPopup delay 0.3 -- 选择“鼠标中键”选项(根据系统语言调整文本,中文系统用这个,英文用"Mouse Button 3") click menu item "鼠标中键" of menu of shortcutPopup end tell end tell -- 可选:关闭系统设置窗口 tell application "System Settings" to quit
注意事项
- 权限设置:必须给运行该脚本的应用(如脚本编辑器、终端)赋予辅助功能权限,路径为:
系统设置>隐私与安全性>辅助功能,添加对应应用后勾选权限。 - 系统语言适配:如果你的Mac是英文系统,把代码中的
"鼠标中键"替换为"Mouse Button 3"。 - 延迟调整:如果脚本执行失败,可适当延长
delay参数的数值,确保UI元素加载完成。
内容的提问来源于stack exchange,提问作者Zax
相关产品推荐
相关产品推荐

