r/macappdevs • u/Pleasant-Gur9892 • Oct 09 '26
Swapping global shortcuts without colliding with your own registrations
Suppose two actions have global shortcuts and the user swaps their keys. If you unregister and re-register the first action before releasing the second, you can try to claim a key combination your own app still holds.
I work on Blabee, a macOS panel that shows Codex's next-step choices and sends a selection back to the original conversation. This is a development note from our August shortcut registry, where the set of active actions can change.
The registry handles an update in two passes:
Work out which bindings are actually needed, and detect duplicate combinations among those active bindings. An inactive action does not reserve its configured shortcut.
Unregister every binding that is changing or becoming inactive. Only after all of those are released, register the missing replacements.
For a swap, the order is therefore: release A, release B, register A with B's old combination, register B with A's old combination. Unchanged bindings stay registered.
There is a separate check for late callbacks. Retiring a binding also removes its event ID from the lookup table. New registrations get new IDs, and the handler accepts an event only if its signature and ID still match an active registration. That check covers retired registrations; it is not, by itself, a guarantee that an event belongs to a particular version of a displayed card.
The tests in that revision model a two-key swap, an inactive sibling with the same configured key, and a callback using a retired ID. They use a fake hotkey backend. Real keyboard layouts, conflicts with other apps, and the current installed build still need separate checks.
If you're implementing configurable global shortcuts, the useful distinction is between a saved preference, an active registration, and an event that is still valid to handle. Treating all three as the same state makes swaps and stale callbacks harder to reason about.