V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
mypursue
V2EX  ›  macOS

怎么弄一个快捷开关 FN + F1 ~F12 的功能键

  •  
  •   mypursue · 9 小时 47 分钟前 · 379 次点击

    有时候我用一些专业软件,或者玩游戏的时候需要用到键盘上的 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

    7 条回复    2026-03-19 19:37:47 +08:00
    di11wei
        1
    di11wei  
       9 小时 17 分钟前
    Karabiner-Elements
    mypursue
        2
    mypursue  
    OP
       9 小时 1 分钟前
    @di11wei 我只需要设置一个快捷开关,这个软件只是复杂化我想要的东西
    everbef
        3
    everbef  
       8 小时 49 分钟前
    1 楼说的那个可能更方便,它是通过记录 app identifier 来实现的。是标准功能键还是媒体键,取决于当前的前台软件
    detecti1914
        4
    detecti1914  
       8 小时 21 分钟前
    同推荐 Karabiner-Elements ,可以按照不同 App 设置
    gauzung
        5
    gauzung  
       7 小时 24 分钟前
    mark 一下, 偶尔玩游戏需要用到 F 按键, 不过我是 TouchBar, 不知道有没有类似的东西
    timmyliu
        6
    timmyliu  
       7 小时 14 分钟前
    PowerToys
    mypursue
        7
    mypursue  
    OP
       4 小时 11 分钟前
    @detecti1914 我知道这个软件强大,但是我的要求很很单一,不想为这个要求去安装一个软件占用运行内容。
    不过已经解决了,reddit 一个人给我写了代码,成功解决我的问题了。
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2614 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:49 · PVG 23:49 · LAX 08:49 · JFK 11:49
    ♥ Do have faith in what you're doing.