Created
June 11, 2014 12:52
-
-
Save ste-fan/c5ad96df9e76d5a92cae to your computer and use it in GitHub Desktop.
Script to toggle display configuration on a laptop
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
#!/bin/sh | |
# Script to toggle display configuration on a laptop | |
# authors: Ruben Verhack, ste-fan | |
config="/tmp/display.conf" | |
# get output names with `xrandr -q` | |
external=VGA1 | |
extMode='--mode 800x600' | |
internal=LVDS1 | |
intMode='--auto' | |
# Check if config exists | |
if ! [ -f $config ]; then | |
# Empty file executes default | |
touch $config | |
fi | |
current=`cat $config` | |
# Check if external monitor is connected | |
if xrandr -q | grep "$external connected"; then | |
# Toggle between 2 states | |
case "$current" in | |
''|'external') | |
# default or was external, now laptop only | |
xrandr --output $internal $intMode --output $external --off | |
echo "internal" > $config | |
;; | |
'internal') | |
# was internal, now external only | |
xrandr --output $internal --off --output $external $extMode | |
echo "external" > $config | |
;; | |
esac | |
#~ # Toggle between 3 states | |
#~ case "$current" in | |
#~ ''|'internal') | |
#~ # default or was internal, now both | |
#~ xrandr --output $internal $intMode --output $external \ | |
#~ --left-of $internal --output $external $extMode | |
#~ echo "dual" > $config | |
#~ ;; | |
#~ 'dual') | |
#~ # was dual, now external only | |
#~ xrandr --output $internal --off --output $external $extMode | |
#~ echo "external" > $config | |
#~ ;; | |
#~ 'external') | |
#~ # was external, now internal only | |
#~ xrandr --output $internal $intMode --output $external --off | |
#~ echo "internal" > $config | |
#~ ;; | |
#~ esac | |
else | |
xrandr --output $internal $intMode | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment