macOS compose key

gen-compose

URL: https://pypi.org/project/gen-compose/

Generates key binding dictionaries using a facility built into macOS, described at https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html

Comes with a companion utility called gen-compose-convert that can accept X compose files as input. Usage:

gen-compose-convert xcompose ./path/to/Compose --keep-comments > xcompose.yaml

Use the output of the above command as input for gen-compose. Usage:

gen-compose xcompose.yaml > ~/Library/KeyBindings/DefaultKeyBinding.dict

This generates a key binding dictionary that uses the non-US backslash character (ยง) as the first character in the chain. What's missing is a way to directly type ยง on a US English keyboard.

hidutil

Since macOS 10.12 Sierra, there has been an ability to do specify simple key re-mappings using the hidutil utility. This functionality is described at https://developer.apple.com/library/archive/technotes/tn2450/_index.html

Command to check current key mappings:

hidutil property --get "UserKeyMapping"

Command to map right Option key to ยง:

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x7000000E6,"HIDKeyboardModifierMappingDst":0x700000064}]}'

Auto-run at startup

Effects of hidutil do not persist across reboots. In order to have the key remapping apply automatically, the command needs to run at startup. One method of doing so is by making a LaunchAgent.

Save the following as ~/Library/LaunchAgents/local.RemapRightOptionToNonUsBackslash.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>local.RemapRightOptionToNonUsBackslash</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/hidutil</string>
        <string>property</string>
        <string>--set</string>
        <string>{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x7000000E6,"HIDKeyboardModifierMappingDst":0x700000064}]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

You'll only receive email when they publish something new.

More from 1559
All posts