Skip to content

Instantly share code, notes, and snippets.

@stefancocora
Created December 2, 2015 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefancocora/476bcaa51115cb28b174 to your computer and use it in GitHub Desktop.
Save stefancocora/476bcaa51115cb28b174 to your computer and use it in GitHub Desktop.
script that switches resolution using xrandr to drive the nvidia driver on a macbook pro
#!/bin/bash
# original script here https://gist.github.com/Garland-g/4552263
# This script requires an argument for the resolution width
if [ -z "$1" ]; then
echo "Usage: script.sh resolution_width";
echo " $0 1920 for a scaled resolution";
echo " $0 2880 for going back to max resolution";
exit 1;
fi
erg=$( echo "$1")
check=$(xrandr -q | grep DP-2 | cut -d " " -f 3 | cut -d "x" -f 1)
if [ "$erg" -eq "$check" ]; then
echo "The screen is already at this resolution"
exit 1;
fi
resolution=$(xrandr -q | grep DP-2 | cut -d " " -f 3);
if [ "$resolution" != "2880x1800+0+0" ]; then
xrandr --output DP-2 --scale 1x1;
#Necessary to work around an issue where re-scaling
#only works if the scale is set to 1x1
sleep 3;
fi
scale_w=$(echo "scale=4; $1/2880" | bc; exit );
arg=$(echo "$scale_w""x""$scale_w")
xrandr --output DP-2 --scale $arg
sleep 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment