Out of curiosity, I started digging around ~/Library/Preferences/ just to see what I could find.
Changing preferences and running:
defaults -currentHost read -g
shows you what changes are being written. I was going to write up a short bash script to automate it, but it looks like I was beaten to the punch:
if [ $1 == "emacs" ]; then
echo "Switching to emacs modifiers"
defaults -currentHost write -g $mappingplist '(
HIDKeyboardModifierMappingDst = 4;
HIDKeyboardModifierMappingSrc = 2; },
HIDKeyboardModifierMappingDst = 12;
HIDKeyboardModifierMappingSrc = 10;
HIDKeyboardModifierMappingDst = 2;
HIDKeyboardModifierMappingSrc = 4;
HIDKeyboardModifierMappingDst = 10;
HIDKeyboardModifierMappingSrc = 12;
echo "Switching to default modifiers"
defaults -currentHost delete -g $mappingplist
The script takes one argument, if the
argument is emacs, then it swaps
command and control, if the argument
is anything else it restores the
Hope that works!