Skip to content

Instantly share code, notes, and snippets.

@BlvckBytes
Last active February 20, 2022 10:37
Show Gist options
  • Select an option

  • Save BlvckBytes/dad23669583ba67a439f20cbbdffec3e to your computer and use it in GitHub Desktop.

Select an option

Save BlvckBytes/dad23669583ba67a439f20cbbdffec3e to your computer and use it in GitHub Desktop.
Override keys on macOS in a way that I'm used to
#!/bin/bash
ERR=`launchctl unload dev.blvckbytes.kbremap.plist 2>&1`
launchctl load dev.blvckbytes.kbremap.plist
[ -z "$ERR" ] && echo "Updated launchd!" || echo "Installed launchd!"
<?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>Label</key>
<string>kbremap</string>
<!-- Set the target user -->
<!-- They need to have .config/kbremap/keyremapping.js in ~ (home) -->
<key>UserName</key>
<string>blvckbytes</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<!-- Get remap file content, strip out comments, join all lines, wrap in single quotes and prefix by the required args, then run that using hidutil -->
<string>cat ~/.config/kbremap/keyremapping.js | sed -E 's|^([^/]*)//.*$|\1|g' | awk 'BEGIN {ORS=""; print "property --set \x27"} {ORS=""; print} END {ORS=""; print "\x27"}' | xargs hidutil</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
{
"UserKeyMapping":[
// CAPS_LOCK to ESCAPE
{
"HIDKeyboardModifierMappingSrc": 0x700000039,
"HIDKeyboardModifierMappingDst": 0x700000029
},
// NON_US_BACKSLASH to GRAVE_ACCENT_AND_TILDE
// On DE this overrides (°/^) with (</>)
{
"HIDKeyboardModifierMappingSrc": 0x700000064,
"HIDKeyboardModifierMappingDst": 0x700000035
},
// GRAVE_ACCENT_AND_TILDE to NON_US_BACKSLASH
// On DE this overrides (</>) with (°/^)
{
"HIDKeyboardModifierMappingSrc": 0x700000035,
"HIDKeyboardModifierMappingDst": 0x700000064
}
]
}
#!/bin/bash
hidutil property --set '{"UserKeyMapping":[]}'
echo "Reset mappings!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment