Does anyone know where OSX stores the settings in System Preferences > Keyboard > Modifier Keys?

Ted*_*ton 3 keyboard macos preferences capslock system-preferences

这些存放在哪里?!?

I'm apparently not the only one who wants to know (How can I change modifier keys in "System Preferences > Keyboard > Modifier Keys..."). I've tried watching the System Preferences app with dtruss, but that doesn't seem to be possible on 10.10.3 (which is what I'm on right now), and I'm not even sure that that would be at all useful if System Preferences is just getting settings from cfprefsd. Watching cfprefsd with dtruss doesn't seem to catch the relevant file access.

Does anyone know of an API to get this information? Something in gestalt perhaps?

Ted*_*ton 6

好的-回答我自己的问题。我编写了一个小程序,该程序使用kqueues监视文件系统更改。在“系统偏好设置”中更改设置时,我看着文件系统进行了修改,并且看到:

'/Users/ted/Library/Preferences/ByHost/.GlobalPreferences.3F1C...9C34.plist.V1Ut9hp' kevent: ident=44, filter=KQ_FILTER_VNODE, flags=KQ_EV_ADD|KQ_EV_CLEAR, fflags=KQ_NOTE_WRITE|KQ_NOTE_CHILD|KQ_NOTE_PDATAMASK
Run Code Online (Sandbox Code Playgroud)

因此设置为中~/Library/Preferences/ByHost/.GlobalPreferences.<UUID>.plist。我不确定UUID是什么-与OpenDirectory有关系吗?(更新:显然,此UUID是您计算机的标识符)。

无论如何,在中.GlobalPreferences.<UUID>.plist,我们看到如下条目:

<key>com.apple.keyboard.modifiermapping.1452-610-0</key>
<array>
    <dict>
        <key>HIDKeyboardModifierMappingDst</key>
        <integer>2</integer>
        <key>HIDKeyboardModifierMappingSrc</key>
        <integer>0</integer>
    </dict>
</array>
Run Code Online (Sandbox Code Playgroud)

1452:610是我的2012 Macbook Pro中USB键盘/触控板组合的十进制VID:PID,并且已插入到我的计算机中且已重新映射修饰符设置的任何其他键盘也会有一个类似的条目。0似乎是Caps Lock键,2并且10似乎是左,右Ctrl键,3并且11似乎左右股权,并412似乎是左,右命令。

因此,从上面可以看到,我的Caps Lock键映射到左侧的CTRL。

看起来其中的设置.GlobalPreferences.<UUID>.plist是标准用户默认设置的一部分。这样一来,您就可以轻松轻松地获得这些设置

[[NSUserDefaults standardUserDefaults] objectForKey:@"com.apple.keyboard.modifiermapping-1452-610-0"];
Run Code Online (Sandbox Code Playgroud)