KeyboardShortcuts is a Swift package that adds sandbox-safe, user-assignable global keyboard shortcuts to macOS apps, with SwiftUI and Cocoa recorder views.
Overview
KeyboardShortcuts is a Swift package for macOS apps that need user-customizable global keyboard shortcuts. It is fully sandboxed and compatible with Mac App Store distribution, and is used in several shipping macOS applications.
Developers register strongly typed shortcut names, present a recorder view so users pick key combinations, and listen for events when shortcuts are pressed. The recorder stores choices in UserDefaults and warns if a shortcut conflicts with the system or the app menu. SwiftUI and Cocoa recorder components are both available.
The API supports key-down and key-up listeners, repeating actions while a key is held on newer macOS versions, connecting shortcuts to NSMenuItem entries, and dynamic shortcut names for user-defined actions. It can also record in-app shortcuts without registering global hotkeys when used with bindings.
The package relies on remaining Carbon APIs for global shortcut registration where Apple has not shipped replacements. It does not trigger accessibility permission dialogs, does not support media keys in sandboxed apps, and localizes recorder UI strings.
Key features
- Global hotkey registration
- SwiftUI shortcut recorder view
- Cocoa recorder component
- Conflict detection with system menus
- UserDefaults persistence
- Key-down and key-up listeners
- NSMenuItem shortcut binding
- Sandbox and App Store compatible
Use cases
- macOS menu bar app hotkeys
- User-defined workflow triggers
- Sandboxed utility shortcuts
- In-app customizable bindings
- Repeating actions while key held