Created
April 1, 2014 10:42
-
-
Save itayadler/9911670 to your computer and use it in GitHub Desktop.
A ruby module that retrieves the resolution details of your monitors - based on https://github.com/jhford/screenresolution
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 'active_support/core_ext/object/try' | |
class ScreenResolution | |
#ONLY FOR MAC | |
#Has a dependency on the screenresolution plugin. Install with it with `brew install screenresolution` | |
def self.get | |
#The screenresolution script output is going to STDERR (uses NSLog), so we redirect to STDOUT | |
raw_output = %x(screenresolution get 2>&1) | |
output = raw_output.split("\n") | |
output.map.with_index do |line, i| | |
next if i == 0 | |
raw_resolution = line.split("Display #{i-1}: ")[1] | |
resolution = raw_resolution.split('x') | |
color_refresh_rate = resolution[2].try(:split, '@') | |
color = color_refresh_rate.try(:[], 0) | |
refresh_rate = color_refresh_rate.try(:[], 1) | |
{ | |
width: resolution[0].to_i, | |
height: resolution[1].to_i, | |
color: color.to_i, | |
refresh_rate: refresh_rate.to_i | |
} | |
end.compact | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment