Last active
August 29, 2015 13:56
-
-
Save seveibar/9333157 to your computer and use it in GitHub Desktop.
Repeatedly clicks a location on the screen then outputs a region of the screen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point | |
def initialize(x,y) | |
@x = x | |
@y = y | |
end | |
def x | |
@x | |
end | |
def y | |
@y | |
end | |
end | |
# Get point from mouse coordinates | |
def gpfmc(mc) | |
Point.new( | |
mc.match(/x:([^ ]*)/)[1].to_i, | |
mc.match(/y:([^ ]*)/)[1].to_i | |
) | |
end | |
# GET WINDOW BOUNDS | |
puts "Set window bounds, type anything to start" | |
gets.strip | |
puts "Move mouse to top left corner" | |
topleft_raw = `sleep 5 && xdotool getmouselocation` | |
puts topleft_raw | |
puts "Move mouse to bottom right corner" | |
bottomright_raw = `sleep 5 && xdotool getmouselocation` | |
puts bottomright_raw | |
puts "Move mouse to clicker" | |
clicker = gpfmc(`sleep 5 && xdotool getmouselocation`) | |
tl = gpfmc(topleft_raw) | |
br = gpfmc(bottomright_raw) | |
# GET PAGE NUM | |
puts "How many pages?" | |
num_pages = gets.strip.to_i | |
puts "Removing old res dir" | |
`rm -r res` | |
`mkdir res` | |
`rm book.pdf` | |
# BEGIN CYCLE | |
num_pages.times { |i| | |
`import -window root res/screen.jpg` | |
`convert -crop '#{br.x - tl.x}x#{br.y-tl.y}+#{tl.x}+#{tl.y}' \ | |
res/screen.jpg res/page#{i}.jpg` | |
`sleep .5 && xdotool mousemove #{clicker.x} #{clicker.y}` | |
`sleep .2 && xdotool click 1` | |
} | |
`cd res && convert *.jpg -quality 100 ../book.pdf` | |
`rm -r res` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment