Updating modifier keys from the command line takes no effect 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 &lt;rest of command&gt;
defaults write NSGlobalDomain &lt;rest of command&gt;
defaults write GlobalPreferences &lt;rest of command&gt;


Running OSX 10.9.4 (Mavrics).

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

$ plutil -convert xml1 -o - ~/Library/Preferences/ByHost/.GlobalPreferences.*.plist


&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;com.apple.keyboard.modifiermapping.1452-591-0&lt;/key&gt;
    &lt;array&gt;
        &lt;dict&gt;
            &lt;key&gt;HIDKeyboardModifierMappingDst&lt;/key&gt;
            &lt;string&gt;30064771303&lt;/string&gt;
            &lt;key&gt;HIDKeyboardModifierMappingSrc&lt;/key&gt;
            &lt;string&gt;30064771302&lt;/string&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
            &lt;key&gt;HIDKeyboardModifierMappingDst&lt;/key&gt;
            &lt;string&gt;30064771302&lt;/string&gt;
            &lt;key&gt;HIDKeyboardModifierMappingSrc&lt;/key&gt;
            &lt;string&gt;30064771303&lt;/string&gt;
        &lt;/dict&gt;
    &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;


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

$ defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-591-0 -array \
'&lt;dict&gt;
    &lt;key&gt;HIDKeyboardModifierMappingDst&lt;/key&gt;
    &lt;integer&gt;30064771303&lt;/integer&gt;
    &lt;key&gt;HIDKeyboardModifierMappingSrc&lt;/key&gt;
    &lt;integer&gt;30064771302&lt;/integer&gt;
&lt;/dict&gt;' \
'&lt;dict&gt;
    &lt;key&gt;HIDKeyboardModifierMappingDst&lt;/key&gt;
    &lt;integer&gt;30064771302&lt;/integer&gt;
    &lt;key&gt;HIDKeyboardModifierMappingSrc&lt;/key&gt;
    &lt;integer&gt;30064771303&lt;/integer&gt;
&lt;/dict&gt;'