Skip to content

Instantly share code, notes, and snippets.

@yuu
Created February 29, 2020 05:56
Show Gist options
  • Save yuu/af5280e3142a6a14545b731b6ffa4597 to your computer and use it in GitHub Desktop.
Save yuu/af5280e3142a6a14545b731b6ffa4597 to your computer and use it in GitHub Desktop.
ChangeModifierMapping with Apple Internal Keyboard
#!/bin/bash -x
# https://developer.apple.com/library/archive/technotes/tn2450/_index.html
# https://qiita.com/hetima/items/b475997008dabd567da0
target=`hidutil list |grep 'Apple Internal Keyboard' |head -n 1 |awk 'BEGIN{printf "\{%s","\"VendorID\":"} {printf "%s",$1} {printf "%s",","} {printf "%s","\"ProductID\":"} END{printf "%s\}\n",$2}'`
# 0x700000000
# LeftControl=0xE0
LeftControl=0x7000000E0
# CapsLock=0x39
CapsLock=0x700000039
function mapping() {
hidutil property \
--matching "$target" \
--set "{\"UserKeyMapping\":[ \
{\"HIDKeyboardModifierMappingSrc\":$LeftControl,\"HIDKeyboardModifierMappingDst\":$CapsLock}, \
{\"HIDKeyboardModifierMappingSrc\":$CapsLock,\"HIDKeyboardModifierMappingDst\":$LeftControl} \
]}"
}
function deleteMap() {
hidutil property --set '{"UserKeyMapping":[]}'
}
mapping
#deleteMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment