Remap Caps Lock to Backspace in macOS Sierra in 1 Second

May 27, 2017

This is useful for Colemak users.

There’s a direct way to remap keys in Sierra from command line.

To remap caps lock to backspace, copy paste this command line (without the $ sign).

$ hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x70000002A}]}'

That’s it.

You can check your remappings with this command.

$ hidutil property --get "UserKeyMapping"

Keeping the Change on Restart

The main drawback with this method is that the change is lost on restart. However, there’s a quick (5 seconds) fix to this.Maybe I should have named this blog post Remap Caps Lock to Backspace in macOS Sierra in 6 Seconds, but technically we have already remapped the key and now just want to keep the change. ;) using the defaults tool to run the script on login.This is not technically the “right” way to run a login script. It is deprecated in part because there can only be one script which is hooked this way. I stuck with this technique because it is an order of magnitude easier and quicker. See more information on login scripts here.

Save the remapping command as a script. I used loginscript.sh as the name.

In the directory of the scriptWorking in the directory of the script allows us to set a global path for the script using pwd, which stands for print working directory. A global path, as opposed to a local path, is a path which does not depend on the directory your shell is in. , give the script permission to execute via chmodChmod stands for change mode. Here’s a great article explaining file permissions. .

chmod +x loginscript.sh

To hook loginscript.sh as the login script, type the command

sudo defaults write com.apple.loginwindow LoginHook `pwd`/loginscript.sh

The change should take affect when you restart your computer.

Remap Any Key

You can remap any key by changing the HIDKeyboardModifierMappingSrc (source) and the HIDKeyboardModifierMappingDst (destination).

In our case, the caps lock ID used for the source was 0x700000039 and the backspace ID for the destination was 0x70000002A.

Click here for a link to Apple’s developer site that provides you with usage ID’s for every key.

Sources and Further Reading

I am not an expert on this topic.

Special thanks to Saul Pwanson who guided me while being up for many fascinating conversational detours about computers (more to come on this blog)!

Remap Caps Lock to Backspace in macOS Sierra in 1 Second - May 27, 2017 - Hang Lu Su