Snippets

Luke Powers xrandr scaling script

Created by Luke Powers last modified
#!/bin/bash
#title           :scaling
#description     :This bash script will adjust the scaling factor for xrandr..
#author          :Luke Powers
#email           :luke@lpsystems.net
#date            :20160908
#version         :0.1
#usage           :scaling [-d, -s, -c (0.25-2), -r, -h]
#notes           :Modify the SCALINGDISPLAY variable to contain your display.
#bash_version    :Built on 4.3.46(1)-release
#===============================================================================
SCALINGDISPLAY="`xrandr | grep "connected primary" | awk '{print $1}'`"
if [ "$1" == "-s" ]
  then
    echo "Scaling to 75%..."
    echo ""
    sleep 2
    xrandr --output $SCALINGDISPLAY --scale 0.75x0.75
    echo "Done!"
elif [ "$1" == "-d" ]
  then
    echo "Setting scaling factor to default 100%..."
    echo ""
    sleep 2
    xrandr --output $SCALINGDISPLAY --scale 1x1
    echo "Done!"
elif [ "$1" == "-r" ]
  then
    echo "Resetting scaled desktop at 75%...."
    echo ""
    xrandr --output $SCALINGDISPLAY --scale 1x1
    sleep 1
    xrandr --output $SCALINGDISPLAY --scale 0.75x0.75
    echo "Done!"
elif [ "$1" == "-c" ]
  then
    if (( $(echo "$2 > 0.24" |bc -l) )) &&  (( $(echo "$2 < 2.01" |bc -l) ))
      then
        echo "Setting scaling to `echo "$2 * 100" | bc`%..."
        echo ""
        xrandr --output $SCALINGDISPLAY --scale $2x$2
        echo "Done!"
    else
      echo "You chose an invalid scaling factor."
      echo "Please select a scaling factor between 0.25 and 2"
    fi
elif [ "$1" == "-h" ]
  then
    echo "This script allows you to scale your primary desktop. If you would"
    echo "like to change which display gets scaled then set the"
    echo " \$SCALINGDISPLAY variable in this script to the desired display."
    echo ""
    echo "usage is as follows:"
    echo -e "  \e[3mnote: only use one option\e[0m"
    echo ""
    echo -e "scaling [-d, -s, -c, -r, -h]"
    echo ""
    echo "OPTIONS:"
    echo "-d      Reset scaling factor to the default of 1"
    echo "-s      Set scaling factor to 0.75"
    echo "-r      Reset 0.75 scaling (useful for display errors from -s)"
    echo "-h      help"
    echo ""
    echo "--Experimental--"
    echo "-c [0.25 - 2.0]     Set scaling factor between 0.25 and 2.0. A scaling"
    echo "                   factor higher than 1.0 will probablly break."
    echo "          Example: scaling -c 0.7"
else
    echo "Please select an option: -d, -s, -r or -h for help"
fi

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.