Get Macbook screen size from terminal/bash

Does anyone know of any possible way to determine or glean this information from the terminal (in order to use in a bash shell script)?

On my Macbook Air, via the GUI I can go to "About this mac" > "Displays" and it tells me: Built-in Display, 13-inch (1440 x 900)

I can get the screen resolution from the system_profiler command, but not the "13-inch" bit. I've also tried with ioreg without success. Calculating the screen size from the resolution is not accurate, as this can be changed by the user.

Has anyone managed to achieve this?


The next script:

model=$(system_profiler SPHardwareDataType | \
/usr/bin/perl -MLWP::Simple -MXML::Simple -lane '$c=substr($F[3],8)if/Serial/}{
print XMLin(get(q{}.$c))->{configCode}')

echo "$model"

will print for example:

MacBook Pro (13-inch, Mid 2010)

Or the same without perl but more command forking:

model=$(curl -s$(system_profiler SPHardwareDataType | sed -n '/Serial/s/.*: \(........\)\(.*\)$/\2/p')|sed 's:.*<configCode>\(.*\)</configCode>.*:\1:')
echo "$model"

It is fetched online from apple site by serial number, so you need internet connection.

I've found that there seem to be several different Apple URLs for checking this info. Some of them seem to work for some serial numbers, and others for other machines. e.g:$Serial&Continue=Continue&num=0$Serial$serial (last 4 digits)

However, the first two URLs are the ones that seem to work for me. Maybe it's because the machines I'm looking up are in the UK and not the US, or maybe it's due to their age?

Anyway, due to not having much luck with curl on the command line (The Apple sites redirect, sometimes several times to alternative URLs, and the -L option doesn't seem to help), my solution was to bosh together a (rather messy) PHP script that uses PHP cURL to check the serials against both URLs, and then does some regex trickery to report the info I need.

Once on my web server, I can now curl it from the terminal command line and it's bringing back decent results 100% of the time. I'm a PHP novice so I won't embarrass myself by posting the script up in it's current state, but if anyone's interested I'd be happy to tidy it up and share it on here (though admittedly it's a rather long winded solution to what should be a very simple query). This info really should be simply made available in system_profiler. As it's available through System, I can't see a reason why not.

Hi there for my bash script , under GNU/Linux : I make the follow to save

# Resolution Fix
echo `xrandr --current | grep current | awk '{print $8}'` >> /tmp/width
echo `xrandr --current | grep current | awk '{print $10}'` >> /tmp/height
cat /tmp/height | sed -i 's/,//g' /tmp/height
WIDTH=$(cat /tmp/width)
HEIGHT=$(cat /tmp/height)
rm /tmp/width /tmp/height
echo "$WIDTH"'x'"$HEIGHT" >> /tmp/Resolution
Resolution=$(cat /tmp/Resolution)
rm /tmp/Resolution
# Resolution Fix

and the follow in the same script for restore after exit from some app / game

in some S.O This its execute command directly

ResolutionRestore=$(xrandr -s $Resolution)

But if dont execute call the variable with this to execute the varible content


And the another way you can try its with the follow for example

RESOLUTION=$(xdpyinfo | grep -i dimensions: | sed 's/[^0-9]*pixels.*(.*).*//' | sed 's/[^0-9x]*//')
VRES=$(echo $RESOLUTION | sed 's/.*x//')
HRES=$(echo $RESOLUTION | sed 's/x.*//')

I think you could only get the display model-name which holds a reference to the size:

ioreg -lw0 | grep "IODisplayEDID" | sed "/[^<]*</s///" | xxd -p -r | strings -6 | grep '^LSN\|^LP'

will output something like:


which depends on the display manufacturer. But as you can see the first three numbers in this model name string imply the display-size: 154 == 15.4''


Found a neat solution but it requires an internet connection:

curl -s`system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | cut -c 9-` |
sed 's|.*<configCode>\(.*\)</configCode>.*|\1|'

hope that helps

Need Your Help

Swap odd and even numbers in array

java recursion

I saw this code on this site. It uses a method to sort out an array with even numbers coming out in the front and odd numbers in the back of the array. I was wondering if you could do the same thing

Optimised search using Ajax and keypress

jquery ajax search keypress

I have the following code that I want to use to search a database as a user is typing into a textbox. The code below works fine but it seems a little inefficient, as if a user is typing really fast...