How can I get the current display resolution from the command line in OS X?

5 Answers 5

system_profiler SPDisplaysDataType | grep Resolution
  • 9
    On a Macbook pro (10.8.3) this only returns the LCD's max resolution, not the current/selected display resolution.
    – studgeek
    Commented Jun 3, 2013 at 16:12
  • 1
    On my Air running 10.8.4 with an external display, this shows both the Air's resolution and the external display's resolution, on separate lines. Commented Jul 9, 2013 at 21:59
  • 1
    It displays the current resolution on a MacBook Pro 2011 model, running Mavericks.
    – daviewales
    Commented May 20, 2014 at 14:43
  • 1
    It shows the current resolution on a MBP with OSX 10.9.4 Commented Aug 21, 2014 at 12:28
  • 1
    For a Retina screen, this shows the physical resolution, not the scaled effective resolution. Commented Jul 28, 2017 at 4:38

For a quick reading on the current virtual resolution of a single retina display:

$ osascript -e 'tell application "Finder" to get bounds of window of desktop'
0, 0, 2048, 1280

Results for multi-monitor setups vary based on which display is primary and how they are arranged. Read more here

  • 3
    This works, the answer provided by Gerry is incorrect.
    – Fuzzy
    Commented Oct 30, 2016 at 9:58
  • Great! This is so much faster than system_profiler!
    – d0g
    Commented Nov 16, 2017 at 15:50
  • They give different numbers in case of Retina though.
    – Nakilon
    Commented Apr 29, 2019 at 12:06
  • This is a better solution, since it returns the "logical" resolution when you're using retina graphics. If you're using this in a script and need to put the height and width into variables, this might help: SCREEN_WIDTH=$(osascript -e 'tell application "Finder" to get bounds of window of desktop' | tr -d ',' | awk '{print $3}'); SCREEN_HEIGHT=$(osascript -e 'tell application "Finder" to get bounds of window of desktop' | tr -d ',' | awk '{print $4}')
    – Chris
    Commented Jul 6, 2020 at 3:22

I use the utility screenresolution to get the screen resolution:

$ /usr/local/bin/screenresolution get 2>&1 | grep -oE 'Display 0: [0-9]+' | grep -Eo '[0-9]+$'  

This is a little one-liner I came up to return the the resolution of the main display, that doesn't require any dependencies to be installed on macOS:

system_profiler -json SPDisplaysDataType 2>/dev/null | python -c "import sys,json;d=next(i for i in json.load(sys.stdin)['SPDisplaysDataType'][0]['spdisplays_ndrvs'] if 'spdisplays_main' in i);print d['_spdisplays_pixels']"

If you need to filter based on different criteria, just replace the 'spdisplays_main' in i expression with a more suitable one.

I know someone on the internet will take offence at the fact that this does in fact depend on Python... Python has come bundled with macOS since Jaguar, so even if you're running a Power Macintosh G3 that hasn't been updated in the last 15 years, you won't need to download Python.

  • 1
    This doesn't work for me, I get KeyError: 'spdisplays_ndrvs'. This is because the first item in SPDisplaysDataType is for the integrated graphics card (kHW_IntelUHDGraphics630Item), but I'm using the discrete graphics which is the 2nd item in the list. Also if you're looking for no-dependency solutions, this is a bit more concise and doesn't require python. Though it might be more obtuse. system_profiler -json SPDisplaysDataType | grep _spdisplays_pixels | cut -d '"' -f 4
    – Chris
    Commented Jul 6, 2020 at 3:17
  • 1
    The problem with using grep is that it returns multiple resolutions, use this instead to get the main display system_profiler -json SPDisplaysDataType 2>/dev/null | jq -r '.. | objects | select(.spdisplays_main) | ._spdisplays_pixels'
    – Eva Lacy
    Commented Sep 29, 2021 at 8:04
  • @EvaLacy I prefer the solution of chris with grepbecause it does not depend on jq and I have only one monitor.
    – Timo
    Commented Jan 9 at 16:38
  • How can I change the command to have a pure python script for the resolution instead of sh?
    – Timo
    Commented Jan 9 at 16:39

I wrote displayplacer, which can help with this. Execute displayplacer list and it will show the current resolution (and more info) for all screens.

$ displayplacer list
Persistent screen id: A46D2F5E-487B-CC69-C588-ECFD519016E5
Contextual screen id: 1124216237
Type: 40 inch external screen
Resolution: 3840x2160
Hertz: 60
Color Depth: 4
Origin: (0,0) - main display
Rotation: 0
Resolutions for rotation 0:
  mode 0: res:3840x2160 hz:60 color_depth:4 <-- current mode
  mode 1: res:3840x2160 hz:60 color_depth:8
  mode 2: res:3840x2160 hz:30 color_depth:4
Persistent screen id: 2960D639-F605-5BB4-A53D-A3263008894C
Contextual screen id: 69733451
Type: MacBook built in screen
Resolution: 1680x1050
Hertz: N/A
Color Depth: 4
Origin: (-1680,1291)
Rotation: 0 - rotate internal screen example (may crash computer, but will be rotated after rebooting): `displayplacer "id:2960D639-F605-5BB4-A53D-A3263008894C degree:90"`
Resolutions for rotation 0:
  mode 0: res:1440x900 color_depth:4 scaling:on
  mode 1: res:1440x900 color_depth:8 scaling:on
  mode 2: res:720x450 color_depth:4 scaling:on

grep is a simple approach to parse the output.

$ displayplacer list | grep -e Resolution: -e Scaling:
Resolution: 3840x2160
Resolution: 1680x1050

Also available via Homebrew brew tap jakehilborn/jakehilborn && brew install displayplacer

  • 1
    (1) I assume that you’re the author of this program (the name being the same).  You should say so, clearly and explicitly, as soon as you mention the program.  (2) This would be a better answer if you actually showed how to parse the output of your program to get what the question asks for, rather than just touting your program. … … … … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. Commented Jun 26, 2019 at 4:40
  • 1
    displayplacer is great! If you're working on something personal where new dependencies are fine, I really recommend others check this out. I have setup keyboard shortcuts to call out to displayplacer so I can easily change my resolution depending on the task. It also lets you set display resolutions that aren't possible to choose in the system preferences even if you know about the obscure trick of holding ⌥ while clicking "Scaled". Not sure why this got downvotes. It's an amazing util.
    – Chris
    Commented Jul 6, 2020 at 3:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .