Skip to content

Instantly share code, notes, and snippets.

@indirect
Last active December 19, 2015 03:39
Show Gist options
  • Save indirect/5891371 to your computer and use it in GitHub Desktop.
Save indirect/5891371 to your computer and use it in GitHub Desktop.
Remap capslock to control on all connected keyboards (now with a test to see if it's already done)
$keyboard_ids = 'ioreg -n IOHIDKeyboard -r | grep -E \'VendorID"|ProductID\' | awk \'{ print $4 }\' | paste -s -d\'-\n\' -'
$check = 'xargs -I{} sh -c \'defaults -currentHost read -g "com.apple.keyboard.modifiermapping.{}-0" | grep "Dst = 2" > /dev/null\''
$remap = 'xargs -I{} defaults -currentHost write -g "com.apple.keyboard.modifiermapping.{}-0" -array "<dict><key>HIDKeyboardModifierMappingDst</key><integer>2</integer><key>HIDKeyboardModifierMappingSrc</key><integer>0</integer></dict>"'
exec { 'Remap capslock to control on all keyboards':
command => "${keyboard_ids} | ${remap}",
unless => "${keyboard_ids} | ${check}"
}
ioreg -n IOHIDKeyboard -r | grep -E 'VendorID"|ProductID' | awk '{ print $4 }' | paste -s -d'-\n' - | xargs -I{} /usr/bin/defaults -currentHost write -g "com.apple.keyboard.modifiermapping.{}-0" -array "<dict><key>HIDKeyboardModifierMappingDst</key><integer>2</integer><key>HIDKeyboardModifierMappingSrc</key><integer>0</integer></dict>"
@amiel
Copy link

amiel commented Nov 6, 2013

@indirect I'm trying boxen for the first time, and I'd like to add this to my people/manifests/amiel.pp. Will it work to paste remap.pp in?

@amiel
Copy link

amiel commented Nov 7, 2013

It seems to. Thanks for putting this together!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment