“I need to get the screen size for each device in my fleet”, I was told.
I had to scratch my head for a second and ask some followup questions. Did they mean the currently user-set resolution? The maximum possible resolution of the display?
It turns out, they wanted a way to programatically capture the size of the physical hardware display in inches for use in renaming the Apple laptops in their fleet. They needed to use the display size as part of the laptop hostnames for asset/inventory purposes.
Fair enough! How do we find that? Doesn’t Apple usually include the display size in the model name like “MacBook Air, 13-inch 2020”?
system_profiler
seems like the most obvious choice to find that model name. While it does offer specs related to a display’s resolution, it does not provide the actual display size. You could certainly reverse engineer the display size using the resolution and some pixel math, but it wasn’t the approach I wanted to take and I knew it would be a headache given different PPI specs for various models. You could also create a dictionary with every single model identifier and its screen size and then match them up in a script, but that would be cumbersome and not very future proof. So we’ve got to find something else to work with.