Skip to content

Instantly share code, notes, and snippets.

@miku
Created Sep 20, 2011
Embed
What would you like to do?
Create screenshots with different screen resolutions on OS X with macruby.
#!/usr/bin/env ruby
require "time"
begin
Dir::mkdir("screenshots")
rescue
end
commit = File.new(".git/refs/heads/master", "r").read.strip
directory = "screenshots"
macruby_exe = "/usr/local/bin/macruby"
prefix = "screenshot"
snapper = "$HOME/github/tomafro/macruby-snapper/snapper.rb"
timestamp = Time.now.strftime("%s")
url = "http://localhost:5000/"
screensizes = [
{ :width => 640, :height => 960 }, # iPhone 4
{ :width => 800, :height => 480 }, # wvga
{ :width => 800, :height => 600 }, # old school
{ :width => 1024, :height => 600 }, # netbook, WSVGA
{ :width => 1024, :height => 786 }, # old school, iPad
{ :width => 1200, :height => 800 }, # macbook
{ :width => 1366, :height => 786 }, # netbook
{ :width => 1440, :height => 900 }, # macbook pro
{ :width => 1600, :height => 768 }, # strange
{ :width => 1680, :height => 1050 } # hires macbok
]
fname = "#{directory}/#{prefix}-#{timestamp}-#{commit}.png"
call = "#{macruby_exe} #{snapper} #{url} #{fname}"
system call
puts "#{fname} (#{File.size?(fname) / 1024}kB)"
for size in screensizes do
fname = "#{directory}/#{prefix}-#{timestamp}-#{commit}-#{size[:width]}x#{size[:height]}.png"
call = "#{macruby_exe} #{snapper} --width #{size[:width]} --height #{size[:height]} #{url} #{fname}"
system call
puts "#{fname} (#{File.size?(fname) / 1024}kB)"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment