0

I see a post for Powershell but am asking for the Bash shell instead:

I have a bash script that I want to stop with a simple keypress. It works great with this code:

read -rsn1 input
if [ "$input" = "Z" ]; then
    ps -aux | grep program.sh
    killall program.sh
fi

Except, instead of running, it waits there at this point for the "Z" and nothing happens. Only when I press a different character will it launch, then it works fine.

What I want is for the program to go and keep going, running UNTIL that "Z" is pressed, and for that to be heard even if window focus is on a different window than the terminal the program is running in. Is that feasible?

(Also, this program uses Xdotool, does anyone know if that will count if the "Z" is within an Xdotool script? For example, if I have Xdotool type "I'm Going to the Zoo" will that Z be seen as the same as if I'd typed it in the keyboard? I know this is a different issue but I may want to make the key something like Esc instead if that's the case...but it works great for the "Z" right now aside from the issue I'm describing.)

Thank you!

user1149499
  • 573
  • 4
  • 12
  • 30
  • I don't think there's a way to do it if focus is on a different window. – Barmar Feb 09 '22 at 17:06
  • You would have to configure a hotkey in your window manager to send something to the terminal window. – Barmar Feb 09 '22 at 17:07
  • Okay, @Barmar, thank you for this idea. Now the kicker: I'm not running it by pulling up a terminal, but rather by calling it from a quickstart menu icon and a .desktop file in lxqt. I don't know enough about how these work in concert to know: Is this still running "in a terminal" even if I haven't pulled up a terminal and typed ./program.sh? But the idea for a hotkey makes a lot of sense. I'll sleuth that out a bit... – user1149499 Feb 09 '22 at 19:45
  • I don't know lxqt, so I can't answer that. – Barmar Feb 09 '22 at 19:47
  • No worries, thanks for the suggestion anyway. If you were to do it in a window manager you DO know, what would the process be? (If that's remotely applicable...) – user1149499 Feb 09 '22 at 19:55

0 Answers0