Last active
July 26, 2022 17:49
-
-
Save tylerjohnst/f21e427529eb50b462e0c350fa2df76d to your computer and use it in GitHub Desktop.
Ruby script that resizes the height of a chrome window by a fixed amount of pixels. Useful for debugging CSS/JS animation issues.
This file contains 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
require 'shellwords' | |
def tell_chrome_to(*commands) | |
tell(%Q(application "System Events" to tell application process "Google Chrome"), *commands) | |
end | |
def tell(target, *commands) | |
["tell #{target}", *commands.flatten, 'end tell'] | |
end | |
def osascript(*commands) | |
commands = commands.flatten.map(&Shellwords.method(:escape)) | |
arguments = (["-e"] * commands.length).zip(commands).flatten.join(' ') | |
`osascript #{arguments}`.chomp | |
end | |
def desired_pixels | |
input = gets.strip | |
if input.match?(/q/) | |
exit 0 | |
elsif input == "" | |
input = 1 | |
else | |
input = input.to_i | |
end | |
end | |
begin | |
dimensions = osascript tell_chrome_to("get size of window 1") | |
width, height = dimensions.split(",").map(&:to_i) | |
while true do | |
print "Reduce window height by how many pixels? (1): " | |
height -= desired_pixels | |
puts "Resizing to height: #{height}" | |
osascript tell_chrome_to(tell("window 1", "set {size} to {{#{width}, #{height}}}")) | |
end | |
rescue SystemExit, Interrupt | |
exit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment