Cambio de teclas modificadoras desde la command-line

Como usuario pesado de Emacs, me gusta reasignar mi tecla Caps Lock para que funcione como la tecla Ctrl. Hay un dialog conveniente en el panel de preferences del keyboard para hacer eso. Pero el problema es que esta configuration se pierde después de que alguien inicia session en otra count que no tiene esta preference establecida.

¿Hay alguna manera de hacer lo mismo que el cuadro de dialog del panel de preferences desde la command-line?

  • Iconos de atajo de keyboard extraños en Mac OS 10.6.7
  • ¿Cuáles son las desventajas de conseguir un layout de keyboard extranjero en un MacBook Pro?
  • Atajos de keyboard con una sola tecla?
  • Cómo ampliar el visor de keyboard OS X?
  • Tecla de acceso directo para seleccionar la aplicación "cerrar inesperadamente" dialog
  • ¿Cómo puedo escribir el símbolo "@" a través del escritorio remoto con un keyboard sueco?
  • Yosemite cambia la disposition del keyboard QWERTY
  • ¿Cuáles son las teclas correspondientes al acceso directo?
  • Emacs en Mac OS X - A Alt o Comando?
  • ¿Hay una manera de acceder a los icons de la barra de menus utilizando el keyboard?
  • Apple Wireless Keyboard no se conecta automáticamente al despertar
  • cómo hacer que cada pantalla sea un espacio separado, pero que tenga un atajo de keyboard para mover ambas pantallas al mismo time?
  • 5 Solutions collect form web for “Cambio de teclas modificadoras desde la command-line”

    Cambiar las preferences y ejecutar, defaults -currentHost read -g muestra los cambios que se están escribiendo. Iba a escribir un script de bash corto para automatizar, pero parece que me golpearon hasta el punch:

     #!/bin/bash mappingplist=com.apple.keyboard.modifiermapping 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; })' else echo "Switching to default modifiers" defaults -currentHost delete -g $mappingplist fi #! / bin / bash #!/bin/bash mappingplist=com.apple.keyboard.modifiermapping 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; })' else echo "Switching to default modifiers" defaults -currentHost delete -g $mappingplist fi { #!/bin/bash mappingplist=com.apple.keyboard.modifiermapping 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; })' else echo "Switching to default modifiers" defaults -currentHost delete -g $mappingplist fi }, #!/bin/bash mappingplist=com.apple.keyboard.modifiermapping 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; })' else echo "Switching to default modifiers" defaults -currentHost delete -g $mappingplist fi { #!/bin/bash mappingplist=com.apple.keyboard.modifiermapping 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; })' else echo "Switching to default modifiers" defaults -currentHost delete -g $mappingplist fi }, #!/bin/bash mappingplist=com.apple.keyboard.modifiermapping 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; })' else echo "Switching to default modifiers" defaults -currentHost delete -g $mappingplist fi { #!/bin/bash mappingplist=com.apple.keyboard.modifiermapping 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; })' else echo "Switching to default modifiers" defaults -currentHost delete -g $mappingplist fi }, #!/bin/bash mappingplist=com.apple.keyboard.modifiermapping 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; })' else echo "Switching to default modifiers" defaults -currentHost delete -g $mappingplist fi { #!/bin/bash mappingplist=com.apple.keyboard.modifiermapping 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; })' else echo "Switching to default modifiers" defaults -currentHost delete -g $mappingplist fi 

    El script toma un argumento, si el argumento es emacs, entonces cambia el command y el control, si el argumento es cualquier otra cosa, restaura los valores por defecto.

    http://forums.macrumors.com/showthread.php?t=949280

    Puede utilizar KeyRemap4MacBook con el PCKeyBoardHack . También le permite usar las keys de Emacs en cualquier aplicación de Mac, incluyendo aquellas que no usan Cocoa como aplicaciones de MS.

    Desde "Actualización de las asignaciones de teclas modificadoras a la herramienta de commands por defecto" :

    defaults -currentHost write -g com.apple.keyboard.modifiermapping.1133-50475-0 -array '<dict><key>HIDKeyboardModifierMappingSrc</key><integer>0</integer><key>HIDKeyboardModifierMappingDst</key><integer>2</integer></dict>

    Cambie 1133 y 50475 al proveedor y los ID de producto mostrados por ioreg -n IOHIDKeyboard -r . src 0 y dst -1 desactivarán el locking de mayúsculas .

    defaults -currentHost write -g modifica:

    ~/Library/Preferences/ByHost/.GlobalPreferences.*.plist

    Tienes que cerrar session y volver a aplicar los cambios. Si los valores son cadenas (como en la respuesta de @pithyless), los cambios se muestran en Preferences del sistema pero no tienen ningún efecto.

    Valores de las teclas :

     -1 none 0 caps lock 1 left shift 2 left control 3 left option 4 left command 5 keypad 0 6 help 9 right shift 10 right control 11 right option 12 right command 

    Combinando unas cuantas respuestas juntas, surgí este script que parece funcionar ( asignar Caps-lock a Control ).

     $ keyboard_id = "$(ioreg -n IOHIDKeyboard -r | grep -e VendorID\" -e ProductID | tr -d \"\|[:blank:] | cut -d\= -f2 | tr '\n' -)" $ defaults -currentHost write -g "com.apple.keyboard.modifiermapping.${keyboard_id}0" '( { HIDKeyboardModifierMappingDst = 2; HIDKeyboardModifierMappingSrc = 0; })' { $ keyboard_id = "$(ioreg -n IOHIDKeyboard -r | grep -e VendorID\" -e ProductID | tr -d \"\|[:blank:] | cut -d\= -f2 | tr '\n' -)" $ defaults -currentHost write -g "com.apple.keyboard.modifiermapping.${keyboard_id}0" '( { HIDKeyboardModifierMappingDst = 2; HIDKeyboardModifierMappingSrc = 0; })' 

    Único problema que no parece tener ningún efecto … 🙁

    Actualizaré si lo consigo para trabajar.

    Quería cambiar el mando derecho con las teclas de opción derecha solamente.

    Cuando configuro commands globales y opciones de intercambio en Preferences del sistema …> Teclado> Teclas de modificación …, hay configuration siguiente en el sistema (que funciona como se esperaba):

     $ defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-591-0 ( { HIDKeyboardModifierMappingDst = 30064771299; HIDKeyboardModifierMappingSrc = 30064771298; }, { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771298; HIDKeyboardModifierMappingSrc = 30064771299; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } ) ( $ defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-591-0 ( { HIDKeyboardModifierMappingDst = 30064771299; HIDKeyboardModifierMappingSrc = 30064771298; }, { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771298; HIDKeyboardModifierMappingSrc = 30064771299; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } ) { $ defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-591-0 ( { HIDKeyboardModifierMappingDst = 30064771299; HIDKeyboardModifierMappingSrc = 30064771298; }, { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771298; HIDKeyboardModifierMappingSrc = 30064771299; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } ) }, $ defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-591-0 ( { HIDKeyboardModifierMappingDst = 30064771299; HIDKeyboardModifierMappingSrc = 30064771298; }, { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771298; HIDKeyboardModifierMappingSrc = 30064771299; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } ) { $ defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-591-0 ( { HIDKeyboardModifierMappingDst = 30064771299; HIDKeyboardModifierMappingSrc = 30064771298; }, { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771298; HIDKeyboardModifierMappingSrc = 30064771299; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } ) }, $ defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-591-0 ( { HIDKeyboardModifierMappingDst = 30064771299; HIDKeyboardModifierMappingSrc = 30064771298; }, { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771298; HIDKeyboardModifierMappingSrc = 30064771299; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } ) { $ defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-591-0 ( { HIDKeyboardModifierMappingDst = 30064771299; HIDKeyboardModifierMappingSrc = 30064771298; }, { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771298; HIDKeyboardModifierMappingSrc = 30064771299; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } ) }, $ defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-591-0 ( { HIDKeyboardModifierMappingDst = 30064771299; HIDKeyboardModifierMappingSrc = 30064771298; }, { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771298; HIDKeyboardModifierMappingSrc = 30064771299; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } ) { $ defaults -currentHost read -g com.apple.keyboard.modifiermapping.1452-591-0 ( { HIDKeyboardModifierMappingDst = 30064771299; HIDKeyboardModifierMappingSrc = 30064771298; }, { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771298; HIDKeyboardModifierMappingSrc = 30064771299; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } ) 

    Pero cuando lo modifico, para intercambiar solo el lado derecho como abajo – no funciona:

     $ defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-591-0 '( { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } )' { $ defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-591-0 '( { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } )' }, $ defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-591-0 '( { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } )' { $ defaults -currentHost write -g com.apple.keyboard.modifiermapping.1452-591-0 '( { HIDKeyboardModifierMappingDst = 30064771303; HIDKeyboardModifierMappingSrc = 30064771302; }, { HIDKeyboardModifierMappingDst = 30064771302; HIDKeyboardModifierMappingSrc = 30064771303; } )' 

    Es porque los valores se escriben como cadenas no integers. Usted puede ver que usando:

     $ 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> <? xml version = "1.0" encoding = "UTF-8"?> <?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> 

    Así que la forma correcta de actualizar la configuration es mediante el formatting XML:

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

    Al final, debe cerrar la session e iniciar session de nuevo.

    Loving Apple Products like poisoning (iPhone, iPad, iMac, Macbook, iWatch).