Skip to content

Instantly share code, notes, and snippets.

@eirikb
Last active April 9, 2021 16:49
Show Gist options
  • Star 43 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirikb/c189a7d8406b2897dad0e86086be1b23 to your computer and use it in GitHub Desktop.
Save eirikb/c189a7d8406b2897dad0e86086be1b23 to your computer and use it in GitHub Desktop.
Automated click testing in bash
#!/bin/bash
function click {
scrot out.png
pos=$(findimage out.png $1)
x=$(echo $pos | grep -oP "\d+:" | grep -oP "\d+")
y=$(echo $pos | grep -oP ":\d+" | grep -oP "\d+")
size=$(file $1)
width=$(echo $size | grep -oP "\d+ x" | grep -oP "\d+")
height=$(echo $size | grep -oP "x \d+" | grep -oP "\d+")
x=$(expr $x + $width / 2)
y=$(expr $y + $height / 2)
echo "click $x $y"
xdotool mousemove $x $y click 1
}
click 1.png
sleep 1s
click 2.png
sleep 1s
click 3.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment