- Code: Select all
#!/usr/bin/env bash
echo "
Run this script with no options for 1280x1024.
For any other resolutions, put the horizontal and vertical
sizes on the command line.
Example:
fixdisplay 1400 900
"
# Get the modeline from the command:
# cvt 1280 1024
#
# Use default display resolution if they
# aren't given in the command arguments.
if [[ $1 ]] ; then
horiz_res="$1"
else
horiz_res="1280"
fi
if [[ $2 ]] ; then
vert_res="$2"
else
vert_res="1024"
fi
list=$(cvt $horiz_res $vert_res | awk '/Modeline/ { print $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 " " $10 " " $11 }')
modeline="$list"
echo -e "\nModeline for $horiz_res x $vert_res"
echo "${modeline[0]}"
all_outputs=$(xrandr | awk '/ connected/ { print $1 }')
echo "
If all_outputs = default (see below) then this script
probably won't work. You can try it, or you can abort by
pressing ctrl-c
"
echo -e "\tall_outputs = $all_outputs"
#if $(echo $all_outputs | grep -q ^default) ; then
# echo "Exit due to error."
# exit 1
#fi
#sleep 2
#echo " Enter an output from this list:
#$all_outputs
#: "
#read output
echo -e "\nSelect a video output from the list:"
select output in "$all_outputs" ; do
echo "$output"
break
done
xrandr --newmode disp$horiz_res ${modeline[@]}
sleep 2
echo "1111"
xrandr --addmode "$output" disp$horiz_res
sleep 2
echo "2222"
xrandr --output "$output" --mode disp$horiz_res
echo "3333"
exit 0
Edit: got rid of the -e in the tests for $1 and $2. For some reason, that doesn't seem to work for me lately. This has happened in a couple of scripts. No idea what's up with that.
N.B. This script only works with some monitors, and it doesn't work with my dual monitor setup. Seems like the main problem is how the output gets listed. Names like VGA-1, DVI-blah work better. If you try it, please share the output from xrandr run in a terminal. Thanks.