A minimal script for KDE Plasma (Wayland) that lets you bind a single keyboard shortcut to:
- Launch an app if it's not running
- Focus its window if it is
- Cycle between multiple windows of the same app
Uses kdotool for Wayland-native window management.
- KDE Plasma 5 or 6 (Wayland session)
- kdotool
# Arch / CachyOS
pacman -S kdotool
# Or build from source — see https://github.com/jinliu/kdotool# Clone the repo
git clone https://github.com/ImJustDoingMyPart/kde-run-or-cycle.git
# Copy to your local bin (or anywhere in your $PATH)
cp kde-run-or-cycle/run-or-cycle.sh ~/.local/bin/
chmod +x ~/.local/bin/run-or-cycle.sh- Open System Settings → Keyboard → Shortcuts
- Click Add New → Command or Script
- In the command field, enter the full path to the script followed by the window class and launch command:
/home/youruser/.local/bin/run-or-cycle.sh brave-browser brave - Click Add custom shortcut and press your desired key combination
That's it. The same shortcut will launch the app, focus it, or cycle between its windows.
| App | Command |
|---|---|
| Brave | /home/youruser/.local/bin/run-or-cycle.sh brave-browser brave |
| Konsole | /home/youruser/.local/bin/run-or-cycle.sh konsole konsole |
| Dolphin | /home/youruser/.local/bin/run-or-cycle.sh dolphin dolphin |
| Firefox | /home/youruser/.local/bin/run-or-cycle.sh firefox firefox |
| VS Code | /home/youruser/.local/bin/run-or-cycle.sh code code |
To find the correct class name for an app you want to add:
# Focus the app window, then run:
kdotool getactivewindow
# Returns something like: {4bb44a33-a5d6-4cca-9bb9-10bc9a3ec0f5}
# Search by app name to verify:
kdotool search --class <app-name>If you use Hyprland instead of KDE, add binds to your config:
bind = $mainMod, B, exec, ~/.local/bin/run-or-cycle.sh brave-browser brave
bind = $mainMod, Return, exec, ~/.local/bin/run-or-cycle.sh konsole konsole- Searches for all windows matching the given class via
kdotool search --class - If none found → launches the app with
setsid(detached from the script) - If windows exist → finds the currently active window and activates the next one in the list
- Wraps around to the first window when reaching the end