0

I need make a small script in bash using xdotool. And I have problem with if statements. How to write correctly this instruction.

if [xdotool click 1] then ./myScript.sh fi

% If I make mouseclick I want to execute bashscript Please help.

Gugu
  • 17
  • 1
  • 8

2 Answers2

0
#/bin/bash

xdotool click 1 
EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
 ./myScript.sh 
fi

exit code 0 - means that you program executed successfully

UPD:

 xdotool click 1 && ./myScript.sh
funivan
  • 3,323
  • 1
  • 14
  • 19
0

There is a feature in xdotool called behave to take an action based on some event like mouse-click But...
The specific mouse-click option is not working (apparently a bug),which is:

xdotool search . behave %@ mouse-click exec 'myscript.sh'

Although these commands work with mouse-move / mouse-leave option, which are:

xdotool search . behave %@ mouse-move exec 'myscript.sh'
xdotool search . behave %@ mouse-leave exec 'myscript.sh'

Another solution would be using echo -e like this:

echo -e "\e[?1000h"
while read -n 12; do myscript.sh; done
Arash
  • 400
  • 4
  • 11
  • echo -e "\e[?1000h" this only works on clicking on the terminal window, I think can be extended to whole system if using like this: nohup echo -e "\e[?1000h" – Arash Mar 13 '16 at 20:20