bashmacosshellscreen-sizesystem-profiler

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?


Solution

  • 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:

    https://selfsolve.apple.com/wcResults.do?sn=$Serial&Continue=Continue&num=0 https://selfsolve.apple.com/RegisterProduct.do?productRegister=Y&country=USA&id=$Serial http://support-sp.apple.com/sp/product?cc=$serial (last 4 digits) https://selfsolve.apple.com/agreementWarrantyDynamic.do

    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 Information.app, I can't see a reason why not.