Remap Caps Lock on macOS without any app

· Tech

I have a longer setup that turns Caps Lock into a super key with Hammerspoon. It does a lot: tap for Escape, double tap to toggle, hold to switch apps.

But you don’t need any app for the basic remap. macOS can do this on its own with hidutil. The only catch is that the mapping doesn’t survive a reboot. A small LaunchAgent fixes that.

The LaunchAgent

Save this as ~/Library/LaunchAgents/com.local.capslock-remap.plist:

<?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>com.local.capslock-remap</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/hidutil</string>
<string>property</string>
<string>--set</string>
<string>{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x70000006D}]}</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

Load it:

Terminal window
launchctl load ~/Library/LaunchAgents/com.local.capslock-remap.plist

That’s it. The remap runs on every boot. No app, no background process to babysit.

What this does

So Caps Lock now does nothing, which is great if you keep hitting it by mistake. You can also pick a different HID code if you want to map it to another key.

To check what’s set:

Terminal window
hidutil property --get "UserKeyMapping"

To clear it for the current session:

Terminal window
hidutil property --set '{"UserKeyMapping":[]}'

To remove it for good, unload the agent and delete the plist.