Detect And Switch To External Monitor

#!/bin/bash
xrandr | grep "VGA-1 connected" > /dev/null
if [ $? -eq 0 ]; then
  xrandr --output VGA-1 --mode 1920x1080
  xrandr --output LVDS-1 --off
fi