Last active
March 14, 2023 05:14
-
-
Save karolba/bdba291a4be6e630a1d40c3ca66cae72 to your computer and use it in GitHub Desktop.
My personal key remappings for macos - for "ISO International Layout" keyboards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
common_mapping=( | |
$' {"HIDKeyboardModifierMappingSrc":0x7000000e7, \n' # <!-- from: right command --> | |
$' "HIDKeyboardModifierMappingDst":0x7000000e6}, \n' # <!-- to: right option --> | |
$' \n' # | |
$' {"HIDKeyboardModifierMappingSrc":0x7000000e6, \n' # <!-- from: right option --> | |
$' "HIDKeyboardModifierMappingDst":0x7000000e7}, \n' # <!-- to: right command --> | |
$' \n' # | |
$' {"HIDKeyboardModifierMappingSrc": 0x7000000E0, \n' # <!-- from: left control --> | |
$' "HIDKeyboardModifierMappingDst": 0xFF00000003}, \n' # <!-- to: fn --> | |
$' \n' # | |
$' {"HIDKeyboardModifierMappingSrc": 0x700000039, \n' # <!-- from: caps lock --> | |
$' "HIDKeyboardModifierMappingDst": 0x7000000E0} \n' # <!-- to: left control --> | |
) | |
mapping_with_grave_lines=( | |
$'{"UserKeyMapping": [ \n' | |
$' {"HIDKeyboardModifierMappingSrc":0x700000064, \n' # <!-- from: paragraph and plusminus --> | |
$' "HIDKeyboardModifierMappingDst":0x700000035}, \n' # <!-- to: grave accent and tilde --> | |
$' \n' # | |
$' {"HIDKeyboardModifierMappingSrc":0x700000035, \n' # <!-- from: grave accent and tilde --> | |
$' "HIDKeyboardModifierMappingDst":0x700000064}, \n' # <!-- to: paragraph and plusminus --> | |
$' \n' # | |
"${common_mapping[@]}" | |
$' ]} \n' | |
) | |
# for use with an external logitech bluetooth keyboard with a mac layout: for some reason it already swaps the ` and § keys | |
# even though the keys printed on the keyboard match the apple layout | |
mapping_without_grave_lines=( | |
$'{"UserKeyMapping": [ \n' | |
"${common_mapping[@]}" | |
$' ]} \n' | |
) | |
mapping_with_grave="${mapping_with_grave_lines[*]}" | |
mapping_without_grave="${mapping_without_grave_lines[*]}" | |
# external bluetooth keyboard data: | |
# from `system_profiler -detailLevel full` | |
# MX Keys M Mac: | |
# Address: DC:63:F4:B1:41:7A | |
# Vendor ID: 0x046D | |
# Product ID: 0xB36A | |
# Firmware Version: RBK74.00_0004 | |
# Minor Type: Keyboard | |
# Services: 0x400000 < BLE > | |
# reset all | |
hidutil property --set '{"UserKeyMapping":[]}' | |
# remapping specific to the external keyboard (MX Keys M Mac) | |
#hidutil property --matching '{"ProductID":0xB36A,"VendorID":0x46D}' --set "$mapping_without_grave" | |
# do a general remapping instead because the keyboard disconnecting/connecting seems to break it somehow (?) | |
hidutil property --set "$mapping_without_grave" | |
# mapping for the internal keyboard (got the values from `hidutil list`) | |
hidutil property --matching '{"ProductID":0x281,"VendorID":0x5ac}' --set "$mapping_with_grave" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment