2

The goal: map "Caps Lock" to "Control" from the command-line.

I'm trying to update the modifier keys from the command-line with the following command as explained here and here but to no effect.

$ defaults -currentHost write -g "com.apple.keyboard.modifiermapping.1452-611-0" '(
{
  HIDKeyboardModifierMappingDst = 2;
  HIDKeyboardModifierMappingSrc = 0;
})'

When I do it from the "System preferences" it works right away and seem to be configured the same as when I do it the manually, as seen below:

$ defaults -currentHost read -g "com.apple.keyboard.modifiermapping.1452-611-0"
(
        {
        HIDKeyboardModifierMappingDst = 2;
        HIDKeyboardModifierMappingSrc = 0;
    }
)

This is the same exact result as when running it manually or from the GUI.

When restarting after running the command line, I see that in "System preferences" it's set correctly, like I expect but, it doesn't work. It only works when resetting do default and setting it manually.

I even tried copying the plist file as suggested here again to no effect (even with restart).

Next I tried this with no success (ideas from here):

defaults -currentHost write -globalDomain <rest of command>
defaults write NSGlobalDomain <rest of command>
defaults write GlobalPreferences <rest of command>

Running OSX 10.9.4 (Mavrics).

Any ideas are welcome.

1

It's because values are written as strings not integers. You can see that using:

$ plutil -convert xml1 -o - ~/Library/Preferences/ByHost/.GlobalPreferences.*.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.keyboard.modifiermapping.1452-591-0</key>
    <array>
        <dict>
            <key>HIDKeyboardModifierMappingDst</key>
            <string>30064771303</string>
            <key>HIDKeyboardModifierMappingSrc</key>
            <string>30064771302</string>
        </dict>
        <dict>
            <key>HIDKeyboardModifierMappingDst</key>
            <string>30064771302</string>
            <key>HIDKeyboardModifierMappingSrc</key>
            <string>30064771303</string>
        </dict>
    </array>
</dict>
</plist>

So the right way to update the setting is using XML format:

$ defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-591-0 -array \
'<dict>
    <key>HIDKeyboardModifierMappingDst</key>
    <integer>30064771303</integer>
    <key>HIDKeyboardModifierMappingSrc</key>
    <integer>30064771302</integer>
</dict>' \
'<dict>
    <key>HIDKeyboardModifierMappingDst</key>
    <integer>30064771302</integer>
    <key>HIDKeyboardModifierMappingSrc</key>
    <integer>30064771303</integer>
</dict>'
  • So in the OP's first example, it create an array, with an object in it, and the value inside the object are implicitly string (even though they look like numbers)? – trusktr May 24 '18 at 22:50
  • When setting multiple values all at once, is using the XML syntax that only way to do it to specify types? Is it required? – trusktr May 24 '18 at 23:00
  • @trusktr Yes, values inside PLIST objects are implicitly strings. I don't know PLIST syntax to force the value to be integer. It seems there is no other way, than using XML syntax. – Virus_7 Jun 19 '18 at 1:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .