Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 10th, 2012  |  syntax: None  |  size: 1.42 KB  |  views: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require "rubygems"
  2. begin
  3.   require "rbosa"
  4. rescue
  5.   "You don't have RubyOSA. That's okay but won't be able to automatically activate Excel for screenshots."
  6. end
  7.  
  8. def capture_xls(xls, png)
  9.   `open #{xls}`
  10.   sleep 2
  11.   `screencapture #{png}`
  12.   `mogrify -crop 840x570+14+54 #{png}`
  13. end
  14.  
  15. # Excel should be already open, and it should be assigned to a
  16. # Space with nothing else in it for nice, tidy screenshots.
  17. # Desktop background should be set to plain white, or use Backdrop.app.
  18. # Also you should have "When switching to an application, switch to a ..." box checked
  19. begin
  20.   app = OSA.app("Microsoft Excel")
  21.   app.activate
  22. rescue
  23.   puts "OSA activation of Microsoft Excel didn't work, you'll have to activate it manually."
  24. end
  25.  
  26. `mkdir -p output/examples`
  27.  
  28. # Take screenshots of all Ruby Examples.
  29. `ls content/examples/*.rb`.chomp.split("\n").each_with_index do |f, i|
  30.   puts "processing #{f}..."
  31.  
  32.   png = f.gsub(/rb$/, "png")
  33.   xls = f.gsub(/rb$/, "xls")
  34.  
  35.   `ruby #{f}`
  36.   capture_xls(xls, png)
  37. end
  38.  
  39. # Take screenshots of all Python Examples.
  40. `ls content/examples/*.py`.chomp.split("\n").each_with_index do |f, i|
  41.   exit # Skip processing Python examples for the moment.
  42.  
  43.   puts "processing #{f}..."
  44.  
  45.   png = f.gsub(/\.py$/, "-python.png")
  46.   xls = f.gsub(/\.py$/, "-python.xls")
  47.  
  48.   `python #{f}`
  49.   capture_xls(xls, png)
  50. end
  51.  
  52. # Return to iTerm
  53. begin
  54.   app = OSA.app("iTerm")
  55.   app.activate
  56. rescue
  57. end
clone this paste RAW Paste Data