Skip to content

Instantly share code, notes, and snippets.

@marianopeterson
Created September 18, 2019 20:48
Show Gist options
  • Save marianopeterson/0f72ceed81b9d69932414d5c39e1a142 to your computer and use it in GitHub Desktop.
Save marianopeterson/0f72ceed81b9d69932414d5c39e1a142 to your computer and use it in GitHub Desktop.
keyboard function
function keyboard {
local OS_KEY="0x7000000E2"
local LEFT_ALT_KEY="0x7000000E3"
local SRC='"HIDKeyboardModifierMappingSrc"'
local DST='"HIDKeyboardModifierMappingDst"'
usage() {
echo "usage: ${FUNCNAME[1]} [-h | mac | win ]"
echo ""
echo " Toggles keyboard mapping between Mac and Windows keyboards"
echo ""
echo " mac Restores factory settings by removing key overrides"
echo " win Remaps the [⊞ WIN] key to [⌥ Option], and the [Alt] key to [⌘ Command]"
}
if [[ $# -eq 0 ]]; then
usage
return
fi
case "$1" in
-h|--help|help)
usage
return ;;
apple|mac|macos|reset)
# reset them to do their normal thing
hidutil property --set "{\"UserKeyMapping\":[ {$SRC:$OS_KEY, $DST:$OS_KEY}, {$SRC:$LEFT_ALT_KEY, $DST:$LEFT_ALT_KEY} ]}"
return ;;
microsoft|ms|win|windows)
# swap command and alt keys
hidutil property --set "{\"UserKeyMapping\":[ {$SRC:$OS_KEY, $DST:$LEFT_ALT_KEY}, {$SRC:$LEFT_ALT_KEY, $DST:$OS_KEY} ]}"
return ;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment