k-o-e
5/2/2020 - 10:09 AM

Multi Monitor Switcher

# Script to switch monitors
# Assumes two monitors (left: DP-0, right: HDMI-0)
# Expected arguments 'l', 'r' or none
# Copy to /usr/bin/m & chmod +x
# Now accessible from Alt+F2 > m

# Define left & right monitor
MONITOR_LEFT="DP-0"
MONITOR_RIGHT="HDMI-0"

if [ -z $1 ]
then
  # Both Monitors
  echo All Monitors On
  xrandr --output $MONITOR_LEFT --auto
  xrandr --output $MONITOR_RIGHT --auto --right-of DP-0
elif [ "$1" = "r" ]
then
  # Right Monitor Only
  echo Switching to Right
  xrandr --output $MONITOR_LEFT --off
  xrandr --output $MONITOR_RIGHT --auto
elif [ "$1" = "l" ]
then
  # Left Monitor Only
  echo Switching to Left
  xrandr --output $MONITOR_LEFT --auto
  xrandr --output $MONITOR_RIGHT --off
else
  # All Monitors
  echo Do Nothing
fi