Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Change screen resolution on the command line System
At work, we run lots of tests for our product. We also reboot the headless minis after each reboot and want to with certainty that they are using the correct resolution. Our configuration management tool works best with command line applications. After searching around, I discovered that there isn't an application that could change resolution from the command line that was a native Intel binary.

I did find source to change resolutions, but it completely lacked any error checking and used APIs which were deprecated in 10.6 and absent in 10.7. I ended up writing a program that works on 10.6 and 10.7, has error checking, is released as a universal binary and is GPL code on github in hopes that others can use and help improve it.

Here is the download link for the installer package, and the source is available here.

Here's what it looks like when run:
$ screenresolution get
Display 0: 1280x800x32
$ screenresolution list
Available Modes on Display 0
  1280x800x8 	1280x800x16 	1280x800x32 	1280x800x30 
  1152x720x8 	1152x720x16 	1152x720x32 	1152x720x30 
  1024x768x8 	1024x768x16 	1024x768x32 	1024x768x30 
  1024x768x8 	1024x768x16 	1024x768x32 	1024x768x30 
  1024x640x8 	1024x640x16 	1024x640x32 	1024x640x30 
  800x600x8 	800x600x16 	800x600x32 	800x600x30 
  800x600x8 	800x600x16 	800x600x32 	800x600x30 
  800x500x8 	800x500x16 	800x500x32 	800x500x30 
  640x480x8 	640x480x16 	640x480x32 	640x480x30 
  640x480x8 	640x480x16 	640x480x32 	640x480x30 
  720x480x8 	720x480x16 	720x480x32 	720x480x30 
  720x480x8 	720x480x16 	720x480x32 	720x480x30 

$ screenresolution set 1280x800x32
Setting mode on display 0 to 1280x800x32

[crarko adds: I tested this using the installer package (in 10.7.2), and it works as illustrated above. The command is installed in /usr/local/bin by default, and required no additional fiddling to make it work. You can also build this from the available source code if you have Xcode installed.]
  • Currently 3.86 / 5
  You rated: 4 / 5 (7 votes cast)

Change screen resolution on the command line | 8 comments | Create New Account
Click here to return to the 'Change screen resolution on the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Change screen resolution on the command line
Authored by: kirsch on Dec 02, '11 09:49:51AM

It's nice that you formatted the program's output to make it readable to <b>humans</b>... but it's a lot more useful if you make the output easy to integrate with other command line utilities.

For example, you may want to list only one resolution per line so that the result can be easily piped to grep. There are other things like this that you can do. Just some thoughts. Nice utility though.

[ Reply to This | # ]
Change screen resolution on the command line
Authored by: leamanc on Dec 02, '11 09:41:49PM

I'd say if you are skilled enough to be writing shell scripts that pipe the output of one command to another, then I'd venture a guess that you are familiar enough with awk, sed, or even some perl one-liners to get just the resolutions. :-)

[ Reply to This | # ]
Change screen resolution on the command line
Authored by: wallybear on Dec 05, '11 09:48:21AM
If you want want to list only one resolution per line, just add this:

| grep -v "Available" | tr -s "[:space:]" "\n"

to the command, i.e:

screenresolution list | grep -v "Available" | tr -s "[:space:]" "\n"

That's it.

[ Reply to This | # ]
Change screen resolution on the command line
Authored by: prijker on Dec 02, '11 10:50:12AM

Very, very handy!

Now in Butler, I have an Hotkey with this Applescript code:

ignoring application responses
do shell script "/usr/local/bin/screenresolution set 1024x768x32"
end ignoring

[ Reply to This | # ]
Change screen resolution on the command line
Authored by: cmcfarling on Dec 02, '11 09:48:23PM

I've been wondering how to do this on a G4. I have headless G4 that I remote into. Since no monitor is connected the display resolution options are very limited. The highest I can set it is 1024x768. This is exactly the type of util I would need but as I mentioned, I have an older PPC. Just wondering if anyone is aware on how to set display res from the command line in 10.4 (PPC).

[ Reply to This | # ]
How about the frequency rate?
Authored by: mariocarta on Dec 04, '11 05:39:02AM

It assumes, for me the 1280x1024x32 @ 90Hz and my monitor goes up to 60 Hz only. Can anyone fix it?

Thank you!

[ Reply to This | # ]
Change screen resolution on the command line
Authored by: outer on Dec 05, '11 12:13:10AM

The (mis)usage message could use some massaging. Thankfully the source is easily modifiable and compilable, so this is easy to season-to-taste. But really: bad usage but no help? I'm thinking 1980's mainframe unfriendliness.

[ Reply to This | # ]
Change screen resolution on the command line
Authored by: bobthebob on Dec 08, '11 06:45:47PM

I find it utterly and totally annoying that Apple has not restored this functionality - for me personally it TOTALLY NEGATES the point of having saved searches since inevitably the scope is either too small or far too large.

it's just another example of the 'dumbing-down' of the Mac interface as far as I'm concerned

also - FWIW I have NOT been able to make the Saved Searches hack listed above work (and I'm no stranger to XML). the resulting modified search files do not appear to behave any differently... is there some sort of cache that Spotlight uses to temporarily store these searches?

[ Reply to This | # ]