How to Get Current Screen Resolution from Command Line in Mac OS X
Typically Mac users will retrieve the screen resolution of connected displays through the Displays system preference panel in OS X. There’s certainly nothing wrong with that approach, it’s easy and quick, but because it uses the graphical interface of OS X it’s not necessary helpful for scripting purposes or remote management through Remote Login and SSH connections. In these situations, and plenty of others, you may wish to retrieve the current screen resolutions of displays from the command line in Mac OS X.
You can get the precise screen resolution with the help of the system_profiler command, which pulls detailed system info as a command line version of the Apple System Profiler utility, long bundled with OS X. The syntax to use is simple, and you’ll probably want to clean up the output with grep to just display the resolution.
The system_profiler command for getting just the resolution of connected displays is as follows, as usual with command line syntax be sure the command is on a single line:
system_profiler SPDisplaysDataType |grep Resolution
The usage of sudo is not necessary, but you can prefix the command with it if you wanted to for some reason or another.
Output is easily read and should look something like the following:
$ system_profiler SPDisplaysDataType |grep Resolution
Resolution: 1920 x 1080
If you’re using multiple displays with the Mac, the resolution for each connected screen will be reported back. If the attached external display is a television, the resolution of the TV screen will be reported as 720p or 1080p too.
The command should work in just about every version of Mac OS X, but note that current versions of Yosemite will dump some unnecessary output that should probably be cleaned up with awk if you’re going to use this for scripting. It’s still readable, but it’s a bit cluttered.
Note that you can skip the grep portion of the command if you’d like, doing so reports back extended display details which can also be helpful.
Keep in mind the output shows the active resolution, not the maximum resolution possible on the display. Thus a Retina display will show what’s currently in use in terms of screen real estate, not the maximum possible resolution of the display.