Sample Header Ad - 728x90

Why does pkill not work with rofi?

1 vote
1 answer
745 views
I want to toggle rofi an application launcher with one keybinding. I made a shell script,
#!/bin/bash

rofi -dpi 1 -modi drun -show drun -show-icons
And bound it to some key. This works but to toggle toggle it back to not running, I tried:
pkill -0 rofi || rofi -dpi 1 -modi drun -show drun -show-icons
That won't let rofi start to begin with. I tested pkill emacs || emacs and that does toggle emacs. Could someone tell me how can I fix it for rofi? And, what does the argument "-0" do? I could not find it in the manual. I did find [this](https://blog.wotw.pro/rofi-change-window-location/) , > I spent a decent chunk of time beating my head against this, and then I realized that rofi stores its pid. We can access the pid file via the config, which in turn gives us access to all the information we need. Before I get to the exciting stuff, though, it's important to mention safety. It's a really good idea to limit your process count (somehow) in case you create a runaway script. Speaking from experience, it could be half an hour before you can free up enough memory to switch to another tty and kill everything.
if [[ 10 -lt $(pgrep -c -f "$0") ]]; then
    pkill -f rofi
    pkill -f "$0"
    exit 1
fi
I am not sure if this is exactly what I want or what does that code even do.
Asked by scribe (143 rep)
Mar 21, 2021, 11:47 PM
Last activity: Mar 22, 2021, 02:57 AM