Created
November 28, 2011 12:46
-
-
Save antonio/1400271 to your computer and use it in GitHub Desktop.
Automatically configure screens
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
#!/usr/bin/env ruby | |
EXTERNAL_SCREEN = 'VGA1' | |
LAPTOP_SCREEN = 'LVDS1' | |
def use_external_screen | |
system "xrandr --output #{EXTERNAL_SCREEN} --auto && xrandr --output #{LAPTOP_SCREEN} --off" | |
end | |
def use_laptop_screen | |
system "xrandr --output #{LAPTOP_SCREEN} --auto && xrandr --output #{EXTERNAL_SCREEN} --off" | |
end | |
def is_vga_connected? | |
IO.popen('xrandr -q | grep " connected "').each do |l| | |
return true if l =~ /#{EXTERNAL_SCREEN}/ | |
end | |
return false | |
end | |
loop { | |
if is_vga_connected? | |
use_external_screen | |
else | |
use_laptop_screen | |
end | |
sleep 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, you are absolutely right. I don't use
.xinitrc
though, but I suppose it should work as well