[Freedom-misc] Looking for an autoclicker

zigote at riseup.net zigote at riseup.net
Thu Mar 19 18:06:20 CET 2020

 > WAIT is always a number in chaosmonk's script: the quotes are useless (and  
so are the curly brackets)

Due to the way it is generated and considering that bash does not understand  
floating point numbers - it is always string.

 > I prefer "while true" to "while [ 1 ]" but that is merely a stylistic  

Yes, and ambiguity is a bad style: "while [ 0 ]" also creates an infinite  
loop. If you want to work with numbers instead for an infinite loop you would  
better use "while (( 1 ))". However "true" is shorter and more readable,  
that's why it is the commonly accepted way for infinite loops.

The simplest way to generate a random float between 1 and 2 without any fancy  
gymnastics is:

WAIT=1.$(( RANDOM % 9 ))

Explanation: "$(( RANDOM % 9 ))" is a random int between 0 and 9

Then the whole script is simplified to:

while true; do
     sleep "1.$(( RANDOM % 9 ))"
     xdotool click 1

More information about the Freedom-misc mailing list