Skip to content

Instantly share code, notes, and snippets.

Forked from Garland-g/
Last active August 29, 2015 14:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#Author: Travis Gibson
#This script requires an argument for the resolution width
#Thanks go out to eCharles for a patch in the comments of this link here:
#Get connected adapter
adapter=$(xrandr -q | grep "connected" | cut -d " " -f 1)
if [ -z "$adapter" ]; then
echo "Connected adapter not found. Check xrandr -q."
#Exit if no adapter is connected
exit 1;
if [ -z "$1" ]; then
echo "Usage: <resolution_width>";
exit 1;
erg=$( echo "$1")
check=$(xrandr -q | grep "$adapter" | cut -d " " -f 4 | cut -d "x" -f 1)
if [ "$erg" -eq "$check" ]; then
echo "The screen is already at this resolution"
exit 1;
resolution=$(xrandr -q | grep "$adapter" | cut -d " " -f 3);
if [ "$resolution" != "2880x1800+0+0" ]; then
xrandr --output "$adapter" --scale 1x1;
#Necessary to work around an issue where re-scaling
#only works if the scale is set to 1x1
sleep 3;
scale_w=$(echo "scale=4; $1/2880" | bc; exit );
arg=$(echo "$scale_w""x""$scale_w")
xrandr --output "$adapter" --scale $arg
sleep 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment