How to Get Current Screen Resolution from Command Line in Mac OS X

Aug 31, 2014 - 6 Comments

Terminal in 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.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

6 Comments

» Comments RSS Feed

  1. Peter Payne says:

    Just for any who wander in here, Applescript “get bounds of window of desktop” no longer works, so you’ll need some other workaround like the above, or if using Keyboard Maestro, there are options for getting the screen resolution.

  2. Sumber says:

    Any screenshot?

  3. MU says:

    @ted,

    ‘AS’ Works as expected with a single display.

  4. andrew says:

    At least this could be useful for getting the current relative resolution from a retina (basically 1/2 of the maximum size for most users). You could use system_profiler to see that it is a retina screen, and then this to get the resolution.

    Note that for multiple screens you will have multiple resolutions, one for each display.

    You can get just the retina display’s resolution with a little bit more piping:

    system_profiler SPDisplaysDataType | egrep ‘Resolution|Retina\:’ | fgrep -B 1 ‘Retina:’ | head -n 1 | awk ‘{ print “Retina resolution: “$2” “$3” “$4 }’

  5. Ross says:

    On Yosemite Preview 6 I get two error messages and the resolution of the Retina display is the max, not the current (I’m running 1920 x 1200) working resolution:

    2014-08-31 14:36:06.514 system_profiler[2723:559685] Error loading /System/Library/SystemProfiler/SPNVMeReporter.spreporter: Error Domain=NSCocoaErrorDomain Code=4 “The bundle “SPNVMeReporter.spreporter” couldn’t be loaded because its executable couldn’t be located.” UserInfo=0x7fecca509810 {NSLocalizedFailureReason=The bundle’s executable couldn’t be located., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSBundlePath=/System/Library/SystemProfiler/SPNVMeReporter.spreporter, NSLocalizedDescription=The bundle “SPNVMeReporter.spreporter” couldn’t be loaded because its executable couldn’t be located.}
    2014-08-31 14:36:06.699 system_profiler[2721:559663] Error loading /System/Library/SystemProfiler/SPNVMeReporter.spreporter: Error Domain=NSCocoaErrorDomain Code=4 “The bundle “SPNVMeReporter.spreporter” couldn’t be loaded because its executable couldn’t be located.” UserInfo=0x7f8f48700940 {NSLocalizedFailureReason=The bundle’s executable couldn’t be located., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSBundlePath=/System/Library/SystemProfiler/SPNVMeReporter.spreporter, NSLocalizedDescription=The bundle “SPNVMeReporter.spreporter” couldn’t be loaded because its executable couldn’t be located.}
    Resolution: 2880 x 1800 Retina

  6. ted says:

    You can also use osascript to pull the resolution with AppleScript

    osascript -e ‘tell application “Finder” to get bounds of window of desktop’

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site