Summary
Expose Insomnia's caffeination actions in macOS Spotlight search and the Shortcuts app using the App Intents framework (macOS 14+).
Context
Raycast shows "Caffeinate" and "Decaffeinate" commands in its search bar. We can achieve the same native Spotlight discoverability using AppIntent + AppShortcutsProvider.
Intents to Create
| Intent |
Spotlight Phrase |
Parameters |
CaffeinateIntent |
"Caffeinate Insomnia" |
--display (Bool) |
DecaffeinateIntent |
"Decaffeinate Insomnia" |
— |
ToggleCaffeinateIntent |
"Toggle Insomnia" |
— |
CaffeinateForIntent |
"Caffeinate for 30 minutes" |
duration (Int, minutes) |
CaffeinateUntilIntent |
"Caffeinate until 5pm" |
time (Date) |
StatusIntent |
"Insomnia status" |
— |
Implementation Notes
- Import
AppIntents framework
- Each intent conforms to
AppIntent protocol with static let title: LocalizedStringResource
- Use
openAppWhenRun = false for background execution
- Create
InsomniaShortutsProvider: AppShortcutsProvider to register all intents
- Intents communicate with the running app via
DistributedNotificationCenter or direct InsomniaCore calls
- Titles/descriptions must be constant values (extracted at compile time)
- App must be installed in
/Applications and signed for Spotlight indexing to work
Requirements
- macOS 14+
- App must be signed with Developer ID
- New file:
Sources/Insomnia/Intents/ directory with one file per intent + the shortcuts provider
References
Summary
Expose Insomnia's caffeination actions in macOS Spotlight search and the Shortcuts app using the App Intents framework (macOS 14+).
Context
Raycast shows "Caffeinate" and "Decaffeinate" commands in its search bar. We can achieve the same native Spotlight discoverability using
AppIntent+AppShortcutsProvider.Intents to Create
CaffeinateIntent--display(Bool)DecaffeinateIntentToggleCaffeinateIntentCaffeinateForIntentduration(Int, minutes)CaffeinateUntilIntenttime(Date)StatusIntentImplementation Notes
AppIntentsframeworkAppIntentprotocol withstatic let title: LocalizedStringResourceopenAppWhenRun = falsefor background executionInsomniaShortutsProvider: AppShortcutsProviderto register all intentsDistributedNotificationCenteror directInsomniaCorecalls/Applicationsand signed for Spotlight indexing to workRequirements
Sources/Insomnia/Intents/directory with one file per intent + the shortcuts providerReferences