Instantly share code, notes, and snippets.

@Garland-g /
Last active Sep 21, 2017

What would you like to do?
This is a script that will change the resolution in Linux on a Macbook Pro Retina computer. Nvidia-current is required for the script to function properly. Tested in Ubuntu 13.04 (alpha).
#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:
if [ -z "$1" ]; then
echo "Usage: <resolution_width>";
exit 1;
erg=$( echo "$1")
check=$(xrandr -q | grep DP-2 | 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 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;
scale_w=$(echo "scale=4; $1/2880" | bc; exit );
arg=$(echo "$scale_w""x""$scale_w")
xrandr --output DP-2 --scale $arg
sleep 1;

This comment has been minimized.

Crybyte commented Nov 24, 2013

I'm completely new when it comes to Ubuntu, or linux in general. How do you run this script?


This comment has been minimized.

nathandailo commented Apr 10, 2014

@Avilis In Terminal, navigate to this file and type "sh"


This comment has been minimized.

npcardoso commented Jun 6, 2014

Thanks for sharing this script.
I adapted this script to automatically detect the screen resolution and make the correct adjustments based on those values (
I only tested it in a MBP 11,1 so let me know if it does not work for you.


This comment has been minimized.

omerralbayrak commented Feb 26, 2015

I have macbook pro retina haswell 13' and this code doesn't work for my machine. How can I fix this problem ? Please help me !


This comment has been minimized.

kyrsideris commented Mar 24, 2015

Thanks for sharing. I modified it to automatically discover the adapter's name. In my case the adapter's name was "VGA-0" and not "DP-2" as I am running Ubuntu 14.04.02 on VirtualBox on MacBook Pro 15'.
Tested only in MacBookPro11,2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment