Created
May 30, 2013 05:59
-
-
Save tylevad/5675950 to your computer and use it in GitHub Desktop.
Xrandr/Xinerama automation script
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/bash | |
# Ty Levad - [email protected] | |
# autoxine | |
single=false | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-1|--one) single=true;; | |
esac | |
shift | |
done | |
# Get connected displays | |
OUTPUT="$(xrandr | grep ' connected ')" | |
if $single; then | |
# Prioritize HDMI | |
if echo $OUTPUT | grep -q "HDMI1"; then | |
xrandr --output LVDS1 --off --output VGA1 --off | |
xrandr --output HDMI1 --preferred --primary | |
pactl set-card-profile 0 output:hdmi-stereo | |
# Then VGA | |
elif echo $OUTPUT | grep -q "VGA1"; then | |
xrandr --output LVDS1 --off --output HDMI1 --off | |
xrandr --output VGA1 --preferred --primary | |
pactl set-card-profile 0 output:analog-stereo | |
# Turn built-in display back on | |
elif echo $OUTPUT | grep -q "LVDS1"; then | |
xrandr --output VGA1 --off --output HDMI1 --off | |
xrandr --output LVDS1 --preferred | |
pactl set-card-profile 0 output:analog-stereo | |
else | |
xrandr --auto | |
pactl set-card-profile 0 output:analog-stereo | |
fi | |
else | |
# If both, use both | |
if echo $OUTPUT | grep -q "VGA1" && echo $OUTPUT | grep -q "HDMI1"; then | |
xrandr --output LVDS1 --off | |
xrandr --output HDMI1 --preferred --primary --output VGA1 --left-of HDMI1 --preferred | |
pactl set-card-profile 0 output:hdmi-stereo | |
# HDMI | |
elif echo $OUTPUT | grep -q "HDMI1"; then | |
xrandr --output VGA1 --off | |
xrandr --output LVDS1 --preferred --primary --output HDMI1 --left-of LVDS1 --preferred | |
pactl set-card-profile 0 output:hdmi-stereo | |
# VGA | |
elif echo $OUTPUT | grep -q "VGA1"; then | |
xrandr --output HDMI1 --off | |
xrandr --output LVDS1 --preferred --primary --output VGA1 --left-of LVDS1 --preferred | |
pactl set-card-profile 0 output:analog-stereo | |
# Turn built-in display back on | |
elif echo $OUTPUT | grep -q "LVDS1"; then | |
xrandr --output VGA1 --off --output HDMI1 --off | |
xrandr --output LVDS1 --preferred | |
pactl set-card-profile 0 output:analog-stereo | |
else | |
xrandr --auto | |
pactl set-card-profile 0 output:analog-stereo | |
fi | |
fi | |
nitrogen --restore | |
killall xmobar | |
killall trayer | |
xmonad --restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment