Last active
August 30, 2018 20:59
-
-
Save npcardoso/ff937ebca6fc0a80ea3d to your computer and use it in GitHub Desktop.
This is a script that will change the resolution in Linux on a Macbook Pro Retina computer. Parts of this script were taken from https://gist.github.com/Garland-g/4552263
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/zsh | |
if [[ $# != 2 ]]; then | |
echo "Usage: Res.sh <device> <resolution_width>"; | |
exit 1; | |
fi | |
DEV=$1 | |
WIDTH=$(xrandr | grep $DEV -A1 | tail -n1 | sed 's/ *\([0-9]*\).*$/\1/') | |
HEIGHT=$(xrandr | grep $DEV -A1 | tail -n1 | sed 's/.*x\([0-9]*\).*$/\1/') | |
CURRENT_WIDTH=$(xrandr | grep $DEV | cut -d ' ' -f 3 | sed 's/ *\([0-9]*\).*$/\1/') | |
CURRENT_HEIGHT=$(xrandr | grep $DEV | cut -d ' ' -f 3 | sed 's/.*x\([0-9]*\).*$/\1/') | |
TARGET_WIDTH=$2 | |
SCALE=$(($TARGET_WIDTH.0 / $WIDTH)) | |
TARGET_HEIGHT=$(echo "$(($HEIGHT * $SCALE)))" | cut -d '.' -f1) | |
echo "$DEV ($WIDTH"x"$HEIGHT) from ($CURRENT_WIDTH"x"$CURRENT_HEIGHT) to ($TARGET_WIDTH"x"$TARGET_HEIGHT) with ratio $SCALE"x"$SCALE" | |
if [[ "$TARGET_WIDTH" == "$CURRENT_WIDTH" && "$TARGET_HEIGHT" == "$CURRENT_HEIGHT" ]]; then | |
echo "The screen is already at this resolution" | |
exit 1; | |
elif [[ "$CURRENT_WIDTH" != "$WIDTH" || "$CURRENT_HEIGHT" != "$HEIGHT" ]]; then | |
echo "Setting 1x1 scale" | |
xrandr --output $DEV --scale 1x1; | |
#Necessary to work around an issue where re-scaling | |
#only works if the scale is set to 1x1 | |
sleep 3; | |
fi | |
echo "Setting new scale" | |
arg="$SCALE"x"$SCALE" | |
xrandr --output $DEV --scale $arg |
Can you give me one specific usage example ? (sh force_resolution.sh)
DOESN'T WORK !!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like it expects arguments, so how do you use it?