Hello everyone, I wrote a script for my monitor’s resolution, and I set it to autostart.
But I want to an if
statement so that it only applies these settings if DP-1
is connected.
Is this possible?
My script:
#!/bin/bash
MODE=$(optimus-manager --print-mode | cut -d " " -f 5)
CVT=$(cvt 1920 1080 | tail -1 | cut -d ' ' -f2-)
mName=$(echo $CVT | cut -d ' ' -f1)
xrandr --newmode $CVT
if [[ $MODE == "nvidia" ]]
then
xrandr --addmode DP-1-1 "$mName"
xrandr --output eDP-1-1 --primary --mode 1366x768 --pos 0x312 --rotate normal --output HDMI-1-1 --off --output DP-1-1 --mode $mName --pos 1366x0 --rotate normal
else
xrandr --addmode DP-1 "$mName"
xrandr --output eDP-1 --primary --mode 1366x768 --pos 0x312 --rotate normal --output HDMI-1 --off --output DP-1 --mode $mName --pos 1366x0 --rotate normal
fi
So it might look like:
#!/bin/bash
MODE=$(optimus-manager --print-mode | cut -d " " -f 5)
CVT=$(cvt 1920 1080 | tail -1 | cut -d ' ' -f2-)
mName=$(echo $CVT | cut -d ' ' -f1)
connected=$(Is VGA-1 connected?)
xrandr --newmode $CVT
if [[ $connected == "yes" ]]
then
if [[ $MODE == "nvidia" ]]
then
xrandr --addmode DP-1-1 "$mName"
xrandr --output eDP-1-1 --primary --mode 1366x768 --pos 0x312 --rotate normal --output HDMI-1-1 --off --output DP-1-1 --mode $mName --pos 1366x0 --rotate normal
else
xrandr --addmode DP-1 "$mName"
xrandr --output eDP-1 --primary --mode 1366x768 --pos 0x312 --rotate normal --output HDMI-1 --off --output DP-1 --mode $mName --pos 1366x0 --rotate normal
fi
fi