If you use X11, you can try xdotoolto catch mouse events
It will be something like:
xdotool search --onlyvisible . behave %@ mouse-click getmouselocation
xdotool manual
If you want to run the script in the background, you can use:
./myscript.sh &>/dev/null &
source
share