有时候我用一些专业软件,或者玩游戏的时候需要用到键盘上的 F1~F12 那些快捷键。 但是平常我还是需要关掉,调节音量大小屏幕明暗的。 我目前自己用快捷指令创建了一个 Applescript ,用 AI 写的。但是这个快捷指令只能打开到开关 FN+F1~F2 这个界面,最后还是我要点击开关。 用了不同的 AI ,但是怎么都修改不出可以自动开关,都是只能到那个界面。
代码如下: tell application "System Settings" activate -- 跳转到功能键设置页面 do shell script "open x-apple.systempreferences:com.apple.Keyboard-Settings.extension?FunctionKeys" end tell delay 1 -- 增加一点延迟,确保开关已经加载出来 tell application "System Events" tell process "System Settings" set frontmost to true try -- 核心逻辑:在这个子窗口的所有层级里寻找第一个“开关 (group)”或“复选框” -- 在新版 macOS 中,这种开关往往被识别为可以点击的 group 或 switch -- 尝试路径 A:寻找第一个开关 set theToggle to first checkbox of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1 click theToggle delay 0.3 -- 点击右下角的“完成”按钮 click button "完成" of window 1 on error -- 尝试路径 B:如果 A 失败,尝试通用的 UI 元素点击 try -- 直接通过 UI 元素索引点击,通常这是页面上第一个也是唯一一个开关 click checkbox 1 of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1 click button "完成" of window 1 on error display notification "坐标或路径匹配失败,请检查辅助功能权限。" with title "切换失败" end try end try end tell end tell
1
di11wei 9 小时 17 分钟前
Karabiner-Elements
|
3
everbef 8 小时 49 分钟前
1 楼说的那个可能更方便,它是通过记录 app identifier 来实现的。是标准功能键还是媒体键,取决于当前的前台软件
|
4
detecti1914 8 小时 21 分钟前
同推荐 Karabiner-Elements ,可以按照不同 App 设置
|
5
gauzung 7 小时 24 分钟前
mark 一下, 偶尔玩游戏需要用到 F 按键, 不过我是 TouchBar, 不知道有没有类似的东西
|
6
timmyliu 7 小时 14 分钟前
PowerToys
|
7
mypursue OP @detecti1914 我知道这个软件强大,但是我的要求很很单一,不想为这个要求去安装一个软件占用运行内容。
不过已经解决了,reddit 一个人给我写了代码,成功解决我的问题了。 |