I'm wondering how to run a bash script in the background that will do something (i.e. run a script, or a command, or whatever) whenever a user clicks the mouse. I'd like this to continue running even if the terminal is closed. Any ideas? Thanks!
Asked
Active
Viewed 5,945 times
5
-
can you get your window system to keep accepting input from a closed window? I'd be very surprised if you can. Having an active mouse assumes that there is some process and event-loop in place to accept the input. If you close a window, you have to rely on an outer layer of software to continue processing, and that means to run a script, your outer layer of software will have to know about the script. Maybe you can register it as a right-click event to the parent process (highly unlikely) before the window closes. And bash scripts don't normally take mouse clicks (IMO). Sorry, but good luck. – shellter Dec 02 '11 at 19:14
-
are you talking about a character terminal or X? – Karoly Horvath Dec 02 '11 at 19:17
-
I see two different questions here. For the first, see http://stackoverflow.com/questions/5966903/how-to-get-mousemove-and-mouseclick-in-bash , for the second, see Aamir's answer. – ninjalj Dec 02 '11 at 20:09
3 Answers
5
If you are using X11, you can try xdotool
to catch mouse events
It would be something like:
xdotool search --onlyvisible . behave %@ mouse-click getmouselocation
If you want to run the script in background you can use:
./myscript.sh &>/dev/null &

Alessandro Pezzato
- 8,603
- 5
- 45
- 63
4
if you just want to run bash command in xterm on mouse click (or wheel event) you can try this example:
$ echo -e "\e[?1000h"
$ while read -n 6; do echo hellowworld; done
this is for wheel event (for click set 12 instead)

Ivan M
- 539
- 3
- 13
-
Thank you for finally setting me on the right track! Here is a good reference doc https://invisible-island.net/xterm/ctlseqs/ctlseqs.html (like ?1000l disables ?1000h) – Andy May 08 '20 at 07:22