A simple "Run or Cycle" script for the Niri window manager.
Inspired by kde-run-or-cycle, this script allows you to launch an application if it's not running, or cycle through its open windows if it's already active.
- Niri
jq(for JSON processing)bash
- Clone this repository or download the
run-or-cycle.shscript. - Give it execution permissions:
chmod +x run-or-cycle.sh
- (Optional) Move it to a directory in your PATH, like
~/.local/bin/.
The script takes two arguments:
app_id: The ID of the application (e.g.,com.mitchellh.ghostty,brave-browser).execution_command: The command to launch the app if it's not running.
./run-or-cycle.sh "app_id" "command"To launch or cycle through Ghostty:
./run-or-cycle.sh "com.mitchellh.ghostty" "ghostty"Run the following command in Niri to see all open windows and their app_id:
niri msg windowsLook for the app_id field of the window you want to control.
You can bind the script to a key in your Niri configuration:
binds {
Mod+Return { spawn "path/to/run-or-cycle.sh" "com.mitchellh.ghostty" "ghostty"; }
Mod+B { spawn "path/to/run-or-cycle.sh" "brave-browser" "brave"; }
}MIT License. See LICENSE for more details.