Skip to content

Instantly share code, notes, and snippets.

@eirikb
Last active January 28, 2017 13:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirikb/ac8196beb0b57577a8fc47eb18427bd4 to your computer and use it in GitHub Desktop.
Save eirikb/ac8196beb0b57577a8fc47eb18427bd4 to your computer and use it in GitHub Desktop.
Demo of clicktest.sh

#Demo

##About The demo is meant to show how to make an automated answer to a hn comment, translated from Norwegian to English with these steps:

  1. Click on Chrome address bar.
  2. Type translate.google.com and press enter.
  3. Click on input field.
  4. Type the text for translation and wait for it to translate.
  5. Click "Copy"-button to copy text to clipboard.
  6. Open new tab.
  7. Type hn comment url and press enter.
  8. Click on input field.
  9. Paste translated text.

##Images

1.png

2.png

3.png

4.png

5.png

#!/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
xdotool type "translate.google.com"
xdotool key KP_Enter
sleep 2s
click 2.png
sleep 1s
xdotool type "Absolutt, det burde være ganske enkelt."
sleep 1s
click 3.png
sleep 1s
click 4.png
sleep 1s
xdotool type "https://news.ycombinator.com/reply?id=11869808&goto=item%3Fid%3D11859980"
xdotool key KP_Enter
sleep 1s
click 5.png
xdotool type "$(xclip -o -selection clipboard)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment