The Computer Oracle

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

Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Forest of Spells Looping

--

Chapters
00:00 Question
00:24 Accepted answer (Score 81)
00:34 Answer 2 (Score 16)
01:01 Answer 3 (Score 4)
01:17 Answer 4 (Score 2)
02:08 Thank you

--

Full question
https://superuser.com/questions/447295/h...

Question links:
[image]: https://i.stack.imgur.com/FmmTx.jpg

Answer 1 links:
[here]: http://daringfireball.net/2006/12/displa...

Answer 2 links:
[screenresolution]: https://github.com/jhford/screenresoluti...

Answer 3 links:
[Python has come bundled with macOS since Jaguar]: https://opensource.apple.com/release/mac...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#macos #mac #commandline #terminal #resolution

#avk47



ACCEPTED ANSWER

Score 81


system_profiler SPDisplaysDataType | grep Resolution



ANSWER 2

Score 18


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




ANSWER 3

Score 4


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



ANSWER 4

Score 1


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