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

萝らか妹 提交于 2019-12-01 09:25:49

Ok - answering my own question. I threw together a little program that uses kqueues to watch file system changes. I watched my file system for modifications when I changed the setting in System Preferences, and I saw:

'/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

So the setting is in ~/Library/Preferences/ByHost/.GlobalPreferences.<UUID>.plist. I'm not sure what the UUID is - something do to with OpenDirectory? (UPDATE: apparently this UUID is an identifier for your machine).

Anyways, in .GlobalPreferences.<UUID>.plist, we see entries like:

<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>

1452:610 is the decimal VID:PID for the USB keyboard/trackpad combo in my 2012 Macbook Pro, and any other keyboard that's been plugged in to my computer and has had modifier settings remapped will have a similar entry. 0 seems to be the Caps Lock key, 2 and 10 seem to be left and right CTRL, 3 and 11 seem to be left and right Option, and 4 and 12 seem to be left and right Command.

So from the above, you can see that I have my Caps Lock key mapped to left CTRL.

It looks like the settings in .GlobalPreferences.<UUID>.plist are a part of your standard user defaults. So you can get at these settings easily enough just by doing

[[NSUserDefaults standardUserDefaults] objectForKey:@"com.apple.keyboard.modifiermapping-1452-610-0"];

All user Preferences are stored in ~/Library/Preferences/com.apple.???

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!