Workaround: Global hotkeys for Electron apps on COSMIC Wayland (OpenWhispr example) #3333
nickpitts32
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone — new to Linux here (running Garuda Linux with COSMIC as my desktop). I've been using AI (Claude Code specifically) to help me navigate things I wouldn't otherwise know how to do, and between the two of us we figured out a workaround I wanted to share with the community.
I'm a heavy voice dictation user and wanted to get OpenWhispr working on COSMIC with a global hotkey. After a few hours of troubleshooting, Claude Code reverse-engineered a solution using Electron's Node inspector protocol and COSMIC's native keybinding system. I have no idea if this is the "right" way to do it, but it works great for me.
I also just want to say — COSMIC is the first desktop environment I've genuinely fallen in love with. Coming from Windows and Mac this thing just clicks for me. Happy to be here.
Getting OpenWhispr (and other Electron apps) Working with Global Hotkeys on COSMIC/Wayland
The Problem
COSMIC doesn't yet support the XDG GlobalShortcuts portal, which means Electron apps can't register global keyboard shortcuts. This affects any Electron-based app that relies on a system-wide hotkey — in my case, OpenWhispr, a voice-to-text dictation app.
On GNOME or KDE, OpenWhispr can grab a global hotkey to start/stop dictation. On COSMIC, pressing the hotkey does nothing. Running under XWayland (
--ozone-platform=x11) partially works but breaks text injection into native Wayland apps.The Solution
The workaround uses three pieces:
ydotoolto simulate paste keystrokes (with terminal detection for Ctrl+Shift+V)Step 1: Launch OpenWhispr with the Node Inspector
Edit
~/.local/share/applications/openwhispr.desktop:The
--inspect=19223flag exposes the Electron main process via the V8 inspector protocol, allowing external scripts to execute code inside the app.Step 2: Create the Toggle Script
Save this as
~/.local/bin/whispr-toggleand make it executable (chmod +x):Step 3: Set Up the COSMIC Keybinding
Create
~/.config/cosmic/com.system76.CosmicSettings.Shortcuts/v1/custom:{ (modifiers: [Super], key: "grave"): Spawn("/home/YOUR_USERNAME/.local/bin/whispr-toggle"), }Replace
YOUR_USERNAMEwith your actual username. Log out and back in for the keybinding to take effect.Step 4: Dependencies
Make sure you have these installed:
Ensure
ydotooldis running (it provides the uinput daemon for simulating keypresses on Wayland):systemctl --user enable --now ydotoolHow It Works
start-dictationIPC message to the renderer. Recording begins.stop-dictation. Audio is sent to Groq (or your configured provider) for transcription. The script polls OpenWhispr's SQLite database every 200ms until the transcription appears.wl-copyand simulates a paste keystroke viaydotool(Ctrl+V for regular apps, Ctrl+Shift+V for terminals).Why Not Just Use
toggle-dictation?OpenWhispr's
toggle-dictationIPC message triggers the app's internal paste mechanism, which pastes a stale/cached transcription instead of waiting for the new one. By using separatestart-dictationandstop-dictationmessages and handling paste externally, we get reliable behavior.Broader Applicability
This technique — using
--inspectto expose an Electron app's main process, then controlling it via the V8 inspector protocol — works for any Electron app that needs global hotkey support on COSMIC. The general pattern is:--inspect=PORThttp://localhost:PORT/json, opens a WebSocket to the debugger, and callsRuntime.evaluateto execute code in the main processSpawn()This should become unnecessary once COSMIC implements the GlobalShortcuts portal, but until then it's a solid workaround.
Environment
openwhispr-cosmic-guide.md
Beta Was this translation helpful? Give feedback.
All reactions