Last active
April 10, 2018 04:00
-
-
Save rkubik/fb87678a2fe9cdee737edf3e6ab5b2c3 to your computer and use it in GitHub Desktop.
xrandr resolution
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 | |
#If no argument is specified, ask for it and exit! | |
if [[ -z "$@" ]]; | |
then | |
echo "An argument is needed to run this script"; | |
exit | |
else | |
arg="$@" | |
#Basic check to make sure argument number is valid. If not, display error and exit | |
if [[ $(($(echo $arg | grep -o "\s" | wc --chars) / 2 )) -ne 2 ]]; | |
then | |
echo "Invalid Parameters. You need to specify parameters in the format \"width height refreshRate\"" | |
echo "For example setResolution \"1920 1080 60\"" | |
exit | |
fi | |
#Save stuff in variables and then use xrandr with those variables | |
modename=$(echo $arg | sed 's/\s/_/g') | |
display=$(xrandr | grep -Po '.+(?=\sconnected)') | |
if [[ "$(xrandr|grep $modename)" = "" ]]; | |
then | |
xrandr --newmode $modename $(gtf $(echo $arg) | grep -oP '(?<="\s\s).+') && | |
xrandr --addmode $display $modename | |
fi | |
xrandr --output $display --mode $modename | |
#If no error occurred, display success message | |
if [[ $? -eq 0 ]]; | |
then | |
echo "Display changed successfully to $arg" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment