Ubuntu – Xdotool script to perform mouse moves and clicks

bashscriptsxdotool

I'm new to xdotool and I have a bash script to do some automated clicks for me, but the clicks don't seem to be occurring. I think it's because I'm not selecting the window, though I'm not very confident about that assessment.

Here's what I have so far:

#!/bin/bash

for x in $(seq 1760 45 1895)
do
    for y in $(seq 760 45 985)
    do
        xdotool mousemove x y click 3
        sleep 0.1
        xdotool mousemove x y+20 click 1
        sleep 0.1

    done
done

Best Answer

  • Most importantly, a variable is called using $, and y+20 doesn't work that way. However, you don't even need to calculate that, just use mousemove_relative 0 20:

    #!/bin/bash
    for x in {1760..1895..45}; do
      for y in {760..985..45}; do
        xdotool mousemove --sync $x $y click 3 sleep 0.1 \
        mousemove_relative --sync 0 20 click 1 sleep 0.1
      done
    done
    

    Additional changes I made:

    • substitute the seq subshell using Brace Expansion
    • use xdotool's builtin sleep function → only call it once
    • call mousemove with the --sync option to let it wait until the mouse is actually moved
  • Related Question