Created
February 20, 2025 15:08
-
-
Save C-Loftus/2b1c4682cbcaa4f27ea92b702d0e4b2a to your computer and use it in GitHub Desktop.
Swap capslock and escape on macos
This file contains hidden or 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 | |
| # Check current mapping and extract relevant content | |
| CURRENT_MAPPING=$(hidutil property --get "UserKeyMapping" | grep "HIDKeyboardModifierMappingSrc") | |
| # Define the swap mapping | |
| SWAP_MAPPING='{ | |
| "UserKeyMapping": [ | |
| { | |
| "HIDKeyboardModifierMappingSrc": 0x700000029, | |
| "HIDKeyboardModifierMappingDst": 0x700000039 | |
| }, | |
| { | |
| "HIDKeyboardModifierMappingSrc": 0x700000039, | |
| "HIDKeyboardModifierMappingDst": 0x700000029 | |
| } | |
| ] | |
| }' | |
| # If CURRENT_MAPPING is not empty, that means a remap is currently active, so we clear it | |
| if [[ -n "$CURRENT_MAPPING" ]]; then | |
| hidutil property --set '{"UserKeyMapping": []}' | |
| echo "Caps Lock and Escape keys have been restored to default." | |
| else | |
| hidutil property --set "$SWAP_MAPPING" | |
| echo "Caps Lock and Escape keys have been swapped." | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment