#!/bin/bash # GPLv2 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # Written by Dan Sheadel # This script was written with an EEEPC in mind, and the device names and # resolutions are set with that in mind. # The command #$ xrandr --prop | grep "connected" # will return a couple lines. the one that is "disconnected" will be alternate device, # (VGA in the script), and the "connected" one is the one that is running (LVDS in the script). # You will need the resolution of your device for the vga-is-active function to work properly. sleep=5s #set the length of time to wait between polls in daemon/monitor mode. function vga-is-connected { #this checks for a physical connection return $(xrandr --prop |grep -q "VGA connected") } function vga-is-active { # this line crudely checks to see if the default for the main screen is the active one # For other laptops/computers you would need to find the resolution and replace this with # the default for your system. See header for info. default_res='800 x 480' if xrandr --prop | grep -q "current $default_res" then return 1 else return 0 fi } function vga-enable { # this sets up the VGA out. Depending on the size of the screen and the ability of # your video card, you might want to try connecting differently. echo Enabling VGA output # these commands are a true dual-screen setup, with the mouse going from one to the other # Note that you must use the correct device names here for it to work right. # on the Eeepc, you can't have a monitor wider than 2048x2048. With the Eee's 800x480, # you are left with monitor of dimensions 1248x1568 or less. #$ xrandr --output VGA --right-of LVDS --auto # [LVDS] [VGA] #$ xrandr --output VGA --left-of LVDS --auto # [VGA] [LVDS] #$ xrandr --output VGA --above LVDS --auto # [VGA]/[LVDS] #vertical placement # This command makes both screens mirrored, with the resolution of the VGA monitor xrandr --output VGA --auto } function vga-disable { # Simply kill the VGA output. You likely don't need to tweak this one. echo Disabling VGA output xrandr --output VGA --off } function vga-toggle { if vga-is-active; then vga-disable; else vga-enable; fi } function vga-monitor { #monitors the VGA port, and automatically switches to it when it can vgaactive=0 while true;do if vga-is-connected; then if vga-is-active then vgaactive=1; else vga-enable fi else if [[ $vgaactive == 1 ]] then vga-disable;vgaactive=0; #else echo -n;#do nothing fi fi sleep $sleep done } function print-help { echo "\ enable,on turn on vga output disable,off turn off vga output monitor Watches for when a VGA connector is plugged in, and will then automatically turn on the VGA connection. When the VGA connector is removed, it will then disable the output. daemon same as monitor, but forks into background, and silences output status Returns true if VGA connector is enabled. No real uses come to mind, but it was easy to implement. toggle If VGA is active, kill it. If it's not, attempt it. help print this handy message --help I hate getting an error for --help, so it's in here too. status returns the status" } ### MAIN ### case $1 in enable) vga-is-connected && vga-enable ;; on) vga-is-connected && vga-enable ;; disable) vga-disable ;; off) vga-disable ;; toggle) vga-toggle ;; status) exit vga-is-active ;; monitor) vga-monitor;; #same as monitor, but forks into the background and runs silently daemon) (vga-monitor>/dev/null&) ;; help) print-help ;; --help) print-help ;; *) echo "*usage: $0 enable|disable|toggle|status|daemon|help" ;; esac