hidutilcmd -- Re-map caps lock, tab, `/~, and right-side option (aka alt) keys on 2016--2019 Apple MacBook Pros without physical escape keys.
sudo /path/to/hidutilcmdhidutilcmd must be installed with execute permissions enabled, and the user must be authorized to use sudo (typically as a member of group wheel on Apple macOS systems).
hidutilcmd remaps the physical caps lock key to a logical tab key, the physical tab key to a logical `/~ key, the physical `/~ key to a logical esc key, and the right-side option key (aka alt key) to a logical caps lock key, using Apple macOS’s hidutil utility, intended for use on 2016--2019 Apple MacBook Pros without physical esc keys. The rationale for using the physical caps lock key as a logical tab key and for using the right option (aka alt) key as a logical caps lock key is that caps lock is typically seldom used, whereas the right option key is almost never used.
hidutilcmd must be installed with execute permissions, and should be installed with write permissions disabled for “group” and “other,” e. g.: chmod a+rx,go-w hidutilcmd. On Apple macOS systems, the primary user (aka administrator) will typically be a member of group wheel, allowing invocation of hidutilcmd via sudo.
To allow invoking sudo hidutilcmd without being prompted for the user password, optionally run sudo visudo and append the following line to sudoers:
username ALL = NOPASSWD: /path/to/hidutilcmd
If Apple Terminal be typically launched at startup (e. g., as one of the user’s “Login Items” in macOS), optionally add sudo /path/to/hidutilcmd to your .kshrc or other login shell startup script, e. g.:
hidutil property --get "UserKeyMapping" |tee .DS_Store
if grep \(null\) .DS_Store >/dev/null
then sudo $HOME/Documents/config/hidutilcmd/hidutilcmd
fi
rm .DS_Store
The above shell script snippet first checks to see if the above key remapping already be in effect, and goes on to invoke hidutilcmd if not.
Technical Note TN2450: Remapping Keys in macOS 10.12 Sierra (from Apple macOS Documentation Archive)
USB HID Usage Tables Specification, Section 10: Keyboard/Keypad page.
Having to use sudo to run hidutil to remap keys presents a security risk, as all users on a system who wish to use hidutil must be granted sudo access. Installing hidutilcmd with root as the owner and the setuid bit set (and with the directory wherein hidutilcmd is located, as well as all directories above it all the way up through /, owned by root as required by macOS for this to work) would potentially be a better solution, but does not appear to work in all versions of macOS and is deprecated by Apple.
On the mid-2017 Apple MacBook Pro 15-inch used for testing, pressing the physical caps lock key twice in rapid succession under macOS “Ventura” when Accessibility -> Keyboard -> Full Keyboard Access is enabled in macOS System Settings causes caps lock to become engaged (and the corresponding LED to turn on), even despite the above remapping. The remapped physical right option (aka alt) key can be used to turn caps lock back off in this case.
Last modified: Monday, March 31, 2025 (tested under Apple macOS ‘Ventura’ version 13.7.5)