Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 534
BSUK Avatar asked Nov 10 '22 04:11

BSUK


1 Answers

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:

LP154WT1-SJE1

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''

EDIT

Found a neat solution but it requires an internet connection:

curl -s http://support-sp.apple.com/sp/product?cc=`system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | cut -c 9-` |
sed 's|.*<configCode>\(.*\)</configCode>.*|\1|'

hope that helps

like image 65
dibi Avatar answered Nov 15 '22 06:11

dibi