How can I get the current screen resolution from the command line on OS X?

54

13

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

cwd

Posted 2012-07-10T20:10:22.783

Reputation: 13 508

Answers

76

system_profiler SPDisplaysDataType | grep Resolution

Gerry

Posted 2012-07-10T20:10:22.783

Reputation: 1 041

1It shows the current resolution on a MBP with OSX 10.9.4 – aymericbeaumet – 2014-08-21T12:28:52.657

For a Retina screen, this shows the physical resolution, not the scaled effective resolution. – David Moles – 2017-07-28T04:38:54.173

6On a Macbook pro (10.8.3) this only returns the LCD's max resolution, not the current/selected display resolution. – studgeek – 2013-06-03T16:12:20.993

1On 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. – Jim Stewart – 2013-07-09T21:59:45.710

@studgeek I'm not sure if this is still an issue, but on my Air it displays the current resolution. It's very strange the the Pro would alter this behaviour. – Gerry – 2014-05-10T10:19:20.877

1It displays the current resolution on a MacBook Pro 2011 model, running Mavericks. – daviewales – 2014-05-20T14:43:55.867

12

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

rymo

Posted 2012-07-10T20:10:22.783

Reputation: 928

1This works, the answer provided by Gerry is incorrect. – Fuzzy – 2016-10-30T09:58:04.900

Great! This is so much faster than system_profiler! – Dan – 2017-11-16T15:50:17.990

They give different numbers in case of Retina though. – Nakilon – 2019-04-29T12:06:16.437

3

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]+$'  
1920

Mark Stewart

Posted 2012-07-10T20:10:22.783

Reputation: 618

0

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
Scaling:off
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
Scaling:on
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
Scaling:off
Resolution: 1680x1050
Scaling:on

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

Jake Hilborn

Posted 2012-07-10T20:10:22.783

Reputation: 111

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. – Scott – 2019-06-26T04:40:10.943