system_profiler SPDisplaysDataType
will give you the physical resolution of a Retina display, but it won't give you the effective (scaled) resolution. If you need that, you can sort of get it with osascript
:
$ osascript -e 'tell application "Finder" to get bounds of window of desktop'
0, 0, 2048, 1280
Note that if you're running a multi-monitor setup, this may require some interpretation. For instance, I have a Retina iMac 21" with physical resolution 4096x2304 and scaled resolution 2560x1440; I also have an external portrait monitor running at 1440x2560:
┌─────────┐┌─────────────┐
│ 1440x ││ 2560x1440 │
│ 2560 ││ │
│ ││ │
│ │└─────────────┘
│ │
└─────────┘
When I run the command above, it reports:
-1440, 0, 2560, 2560
These are the bounds of the desktop relative to the upper left corner of the main monitor:
x = -1440 0 2560
┌─────────┐┌─────────────┐ y = 0
│ ││ │
│ Monitor ││ Monitor 0 │
│ 1 ││ │
│ │└─────────────┘ 1440
│ │
└─────────┘ 2560
As you can see, this by itself doesn't actually give you the scaled vertical resolution of the main monitor (although you can figure it out from the physical aspect ratio).
Another option is the GPL'ed utility screenresolution (which is available through Homebrew if you don't want to build it yourself). The command line isn't much like anything else on this earth, but it works:
$ screenresolution get
2018-04-20 10:00:14.935 screenresolution[12084:518367] starting screenresolution argv=screenresolution get
2018-04-20 10:00:14.938 screenresolution[12084:518367] Display 0: 2560x1440x32@0
2018-04-20 10:00:14.939 screenresolution[12084:518367] Display 1: 1440x2560x32@60
As a bonus, it also gives you the color depth in bits and, if available, the refresh rate in Hz.