Giter Club home page Giter Club logo

screenresolution's Introduction

This is a tool that can be used to determine current resolution,
list available resolutions and set resolutions for active displays
on Mac OS 10.6, and possibly above.  I have only tested 10.6.

I used clang for development, but the code seems to compile
just fine with gcc.  The code might not be as well layed out
as it could be, feel free to send a pull request.

Build+Install
====================
Running the following commands in Terminal.app will result in 
dmg with a pkg file being created if the system has Xcode 4.
    
    git clone github.com:jhford/screenresolution
    cd screenresolution
    make dmg

At this point, I'd recommend testing that things work!  I have
written a 'test' makefile target.  Because this script expects two
monitors that both use the same resolution, it mightn't work 
properly for you if you only have one

    make test ORIG_RES=1920x1200x32

This will cause your screen to flicker as it changes the mode a
couple times on each monitor.

The makefiles support the DESTDIR (alternate root) and PREFIX 
variables.  If you don't know what those are, you probably don't
want them.

This will create a DMG file and a PKG file.  If you know or care 
about the differences, you probably know what to do at this point.
If you want to install this program on the system you built it on,
you can run 
    
    open screenresolution.pkg

If you want to put this program on another system, you can choose
between the pkg file, the dmg file, the binaries or use the 
install make target with DESTDIR to specify an alternate root.

Running
====================
There are three commands that this program supports: get, list 
and set.  All three modes operate on active displays [1].

The get mode will show you the resolution of all active displays

    $ screenresolution get
    Display 0: 1920x1200x32
    Display 1: 1920x1200x32
 
 The list mode will show you to the available resolutions of all
 active displays, seperated by various whitespace.

    Available Modes on Display 0
      1920x1200x8   1920x1200x16    1920x1200x32    960x600x8 
      960x600x16    960x600x32      1680x1050x8 	1680x1050x16 
    <snip>
    Available Modes on Display 1
    <snip>

The set command takes a list of modes.  It will apply the modes
in the list of modes to the list of displays, starting with 0.
Modes in excess of the number of active displays will be ignored.
If you wish to set a monitor but not the lower numbered displays,
there is a keyword 'skip' which can be subsituted for a resolution.
This keyword will cause the first display to be skipped.  If you
specify more resolutions than you have active screens, the extra
resolutions will be ignored.

Example 1:
    This example works with one or more screens
    $ screenresolution set 800x600x32
Result 1:
    The main display will change to 800x600x32, second screen
    will not be changed

Example 2:
    This example assumes two screens
    $ screenresolution set 800x600x32 800x600x32
Result 2:
    The first and second monitor on the system will be set to 
    800x600x32

Example 3:
    This example assumes two screens
    $ screenresolution set skip 800x600x32
    This will not touch the first screen but will set the second
    screen to 800x600x32


[1]See discussion point for explanation of what active display means.
http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html#//apple_ref/c/func/CGGetActiveDisplayList

screenresolution's People

Contributors

colin-mcdonald avatar jhford avatar jszakmeister avatar lantz avatar miloszlakomy avatar mistydemeo avatar mjburghard avatar rnewman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

screenresolution's Issues

The output is more verbose than the README says

The README says:

The get mode will show you the resolution of all active displays

    $ screenresolution get
    Display 0: 1920x1200x32
    Display 1: 1920x1200x32

I get a lot more than that:

2014-06-29 17:32:08.230 screenresolution[40457:507] starting screenresolution argv=screenresolution get
2014-06-29 17:32:08.236 screenresolution[40457:507] Display 0: 1280x800x32@0

The extra looks like logging info. But I think it would be nicer if the actual output looked like the README said.

Also, I noticed that all output I ever get from screenresolution is to stderr. If I do screenresolution get 2>/dev/null I get no output whatsoever.

Tab completion

When using Bash I want to be able to use tab completion with screenresolution. It should also list available resolutions after writing "screenresolution set " and pressing tab.

make dmg throws error

My model: MacBook Air Early 2015 Version 10.13.2
When I do make dmg after cloning the repo and cd-ing into it, it throws the following output:

dev@mehulmpt:~/screenresolution$ make dmg
sed -e "s/@VERSION@/\"1.7dev\"/" < version-tmpl.h > version.h
clang   -arch i386 -arch x86_64 main.c -c -o main.o
main.c:175:26: warning: implicit declaration of function 'MIN' is invalid in C99
      [-Wimplicit-function-declaration]
        idxDisplayMode = MIN(idxDisplayMode, numModes - 1);
                         ^
1 warning generated.
main.c:175:26: warning: implicit declaration of function 'MIN' is invalid in C99
      [-Wimplicit-function-declaration]
        idxDisplayMode = MIN(idxDisplayMode, numModes - 1);
                         ^
1 warning generated.
clang   -arch i386 -arch x86_64 cg_utils.c -c -o cg_utils.o
cg_utils.c:25:30: warning: 'CGDisplayModeCopyPixelEncoding' is deprecated: first
      deprecated in macOS 10.11 [-Wdeprecated-declarations]
        CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
                                    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDirectDisplay.h:176:34: note: 
      'CGDisplayModeCopyPixelEncoding' has been explicitly marked deprecated
      here
CG_EXTERN CFStringRef __nullable CGDisplayModeCopyPixelEncoding(
                                 ^
1 warning generated.
cg_utils.c:25:30: warning: 'CGDisplayModeCopyPixelEncoding' is deprecated: first
      deprecated in macOS 10.11 [-Wdeprecated-declarations]
        CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
                                    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDirectDisplay.h:176:34: note: 
      'CGDisplayModeCopyPixelEncoding' has been explicitly marked deprecated
      here
CG_EXTERN CFStringRef __nullable CGDisplayModeCopyPixelEncoding(
                                 ^
1 warning generated.
clang   -arch i386 -arch x86_64 -framework Foundation -framework ApplicationServices main.o cg_utils.o -o screenresolution
Undefined symbols for architecture i386:
  "_MIN", referenced from:
      _listAvailableModes in main.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [screenresolution] Error 1

Subsequent calls to make dmg throw the following errors:

dev@mehulmpt:~/screenresolution$ make dmg
clang   -arch i386 -arch x86_64 -framework Foundation -framework ApplicationServices main.o cg_utils.o -o screenresolution
Undefined symbols for architecture i386:
  "_MIN", referenced from:
      _listAvailableModes in main.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [screenresolution] Error 1

What should I do?

output of list could use a newline at the end

On Mountain Lion when I do screenresolution get, I see the following:

2013-11-05 23:20:09.625 screenresolution[2274:707] starting screenresolution argv=screenresolution list
Available Modes on Display 0
  1280x800x32@0         1152x720x32@0           1024x768x32@0
  1024x640x32@0         800x600x32@0            800x500x32@0
  640x480x32@0          720x480x32@0         users/foo $

Look where the bash prompt is. It shouldn't be on the last get line, it should start fresh on a new line.

Add ability to make an online display active or deactivate a display

It'd be neat to be able to turn a display that is plugged in but off on, or an active display off.

screenresolution 800x600x32 off
-should turn display 0 to 800x600x32
-should deactivate display 1
screenresolution off 800x600x32
-should deactivate display 0
-should set display 1 to 800x600x32
screenresolution skip off
-should skip display 0
-should deactivate display 1

Listed resolution shows as "not available"

I can't set any resolutions for my secondary display. Here's the output.

2012-10-03 00:07:38.467 screenresolution[59327:707] starting screenresolution argv=./screenresolution list 
Available Modes on Display 0
  2560x1440x16@0        2560x1440x32@0          2560x1440x30@0       
  1280x720x16@0         1280x720x32@0           1280x720x30@0        
  640x480x16@0          640x480x32@0            640x480x30@0         
  800x600x16@0          800x600x32@0            800x600x30@0         
  1024x768x16@0         1024x768x32@0           1024x768x30@0        
  1280x1024x16@0        1280x1024x32@0          1280x1024x30@0       
  1344x756x16@0         1344x756x32@0           1344x756x30@0        
  1600x900x16@0         1600x900x32@0           1600x900x30@0        
  1680x1050x16@0        1680x1050x32@0          1680x1050x30@0       
  1920x1080x16@0        1920x1080x32@0          1920x1080x30@0       
  1600x1200x16@0        1600x1200x32@0          1600x1200x30@0       
  1920x1200x16@0        1920x1200x32@0          1920x1200x30@0       
Available Modes on Display 1
  1920x1080x16@60       1920x1080x32@60         1920x1080x30@60      
  1280x720x16@60        1280x720x32@60          1280x720x30@60       
  720x480x16@60         720x480x32@60           720x480x30@60        
  640x480x16@60         640x480x32@60           640x480x30@60        
  720x576x16@50         720x576x32@50           720x576x30@50        
  1280x720x16@50        1280x720x32@50          1280x720x30@50       
  1920x1080x16@50       1920x1080x32@50         1920x1080x30@50      
  1920x1080x16@50       1920x1080x32@50         1920x1080x30@50      
  1920x1080x16@60       1920x1080x32@60         1920x1080x30@60      
  1366x768x16@60        1366x768x32@60          1366x768x30@60       
  1920x1080x16@60       1920x1080x32@60         1920x1080x30@60      
  800x600x16@60         800x600x32@60           800x600x30@60        
  1024x768x16@60        1024x768x32@60          1024x768x30@60       
  1024x576x16@60        1024x576x32@60          1024x576x30@60       
  1280x960x16@60        1280x960x32@60          1280x960x30@60       
  1344x1008x16@60       1344x1008x32@60         1344x1008x30@60      
  1344x756x16@60        1344x756x32@60          1344x756x30@60       
  1600x900x16@60        1600x900x32@60          1600x900x30@60       
megamind:screenresolution jonathan$ ./screenresolution set skip 1920x1080x16@60
2012-10-03 00:07:41.541 screenresolution[59329:707] starting screenresolution argv=./screenresolution set skip 1920x1080x16@60 
Skipping display 0
2012-10-03 00:07:41.546 screenresolution[59329:707] Error: mode [email protected] not available on display 1

I have Mountain Lion, could this be the problem?

Also, is there a way to select "720p" as displayed in the display resolution options (I know the resolution is 1280x720) as a shortcut?

Need option to set interlaced property

We have some AV setups that incorrectly report interlaced in their EDID. We would like to be able to force this to be off/on as needed. I believe currently this setting is simply mirrored from the current display settings.

Rounding error on Master and OS X Mavericks

Just built this from source today, first time user and ran into this bug. If I explicitly set the refresh rate it work work, so it looks like a float rounding issue:

Jon-Staceys-iMac:screenresolution jon$ ./screenresolution set 1024x768x32
2013-10-30 20:38:23.815 screenresolution[1164:507] starting screenresolution argv=./screenresolution set 1024x768x32 
2013-10-30 20:38:23.820 screenresolution[1164:507] Warning: no refresh rate specified, assuming 60Hz
2013-10-30 20:38:23.822 screenresolution[1164:507] Error: mode [email protected] not available on display 0
Jon-Staceys-iMac:screenresolution jon$ ./screenresolution set 1024x768x32@0
2013-10-30 20:38:38.603 screenresolution[1165:507] starting screenresolution argv=./screenresolution set 1024x768x32@0 
2013-10-30 20:38:38.609 screenresolution[1165:507] set mode on display 0 to 1024x768x32@0

Can't create package

I have Xcode installed but when I run the make DMG command it gives an error 127. Tried running sudo and still gave same error. Not sure what happened. Any chance this could possibly be added to homebrew?

Question (not issue); Macbook Pro doesn't support 16:9

Hi,

Thanks for the great utility, I'm curious though why my Macbook won't support 16:9 resolutions? Any pointers where to find out more? It support 4:3, and 1.6:1 (whatever that is!) see below...

box$ screenresolution list
2014-02-25 20:55:03.231 screenresolution[27894:507] starting screenresolution argv=screenresolution list 
Available Modes on Display 0
  2560x1600x32@0        1280x800x32@0           2048x1280x32@0       
  1650x1050x32@0        1440x900x32@0           1152x720x32@0        
  840x524x32@0          1024x768x32@0           800x600x32@0         
  640x480x32@0

Doesn't build on Sierra (GM) with Xcode 8

On the Sierra GM with Xcode 8 and the CLT for Xcode 8, building from the latest commit results in the following:

sed -e "s/@VERSION@/\"1.7dev\"/" < version-tmpl.h > version.h
clang   -arch i386 -arch x86_64 main.c -c -o main.o
clang   -arch i386 -arch x86_64 cg_utils.c -c -o cg_utils.o
clang   -arch i386 -arch x86_64 -framework Foundation -framework ApplicationServices main.o cg_utils.o -o screenresolution
Undefined symbols for architecture x86_64:
  "_MIN", referenced from:
      _listAvailableModes in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [screenresolution] Error 1

Prior to the failure point, there are also warnings emitted:

sed -e "s/@VERSION@/\"1.7dev\"/" < version-tmpl.h > version.h
clang   -arch i386 -arch x86_64 main.c -c -o main.o
main.c:175:26: warning: implicit declaration of function 'MIN' is invalid in C99
      [-Wimplicit-function-declaration]
        idxDisplayMode = MIN(idxDisplayMode, numModes - 1);
                         ^
1 warning generated.
main.c:175:26: warning: implicit declaration of function 'MIN' is invalid in C99
      [-Wimplicit-function-declaration]
        idxDisplayMode = MIN(idxDisplayMode, numModes - 1);
                         ^
1 warning generated.
clang   -arch i386 -arch x86_64 cg_utils.c -c -o cg_utils.o
cg_utils.c:25:30: warning: 'CGDisplayModeCopyPixelEncoding' is deprecated: first
      deprecated in macOS 10.11 [-Wdeprecated-declarations]
        CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
                                    ^
/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDirectDisplay.h:174:34: note:
      'CGDisplayModeCopyPixelEncoding' has been explicitly marked deprecated here
CG_EXTERN CFStringRef __nullable CGDisplayModeCopyPixelEncoding(
                                 ^
1 warning generated.
cg_utils.c:25:30: warning: 'CGDisplayModeCopyPixelEncoding' is deprecated: first
      deprecated in macOS 10.11 [-Wdeprecated-declarations]
        CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
                                    ^
/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDirectDisplay.h:174:34: note:
      'CGDisplayModeCopyPixelEncoding' has been explicitly marked deprecated here
CG_EXTERN CFStringRef __nullable CGDisplayModeCopyPixelEncoding(
                                 ^
1 warning generated.

When building from the 1.6 release tarball, I get the warnings but not the build failure.

Custom Resolutions not supported?

My MacBook air natively supports 1280x810 resolution if I hold Options key while clicking on "Scaled Resolution" in the settings, but I cannot set 1280x810 resolution through ./screenresolution command because that resolution is not present.

How do I select a custom (but available) 16:9 resolution through terminal?

Does not list / use HIDPI resolutions

On a MacBook with a Retina display, resolutions with hi-dpi are not listed and seemingly not accessible. For example:

$ ./screenresolution list
2014-08-05 15:33:43.994 screenresolution[13007:507] starting screenresolution argv=./screenresolution list
Available Modes on Display 0
   640x 480x32@0        1024x 768x32@0          1440x 900x32@0
   800x 600x32@0        1152x 720x32@0          1650x1050x32@0
   840x 524x32@0        1280x 800x32@0          2048x1280x32@0
  1024x 768x32@0 
$ ./screenresolution get
2014-08-05 15:33:48.503 screenresolution[13010:507] starting screenresolution argv=./screenresolution get
2014-08-05 15:33:48.509 screenresolution[13010:507] Display 0: 1280x800x32@0
$ ./screenresolution set 1280x800x32@0
2014-08-05 15:34:03.217 screenresolution[13012:507] starting screenresolution argv=./screenresolution set 1280x800x32@0
2014-08-05 15:34:03.223 screenresolution[13012:507] set mode on display 0 to 1280x800x32@0
$ ./screenresolution get
2014-08-05 15:34:07.031 screenresolution[13017:507] starting screenresolution argv=./screenresolution get
2014-08-05 15:34:07.037 screenresolution[13017:507] Display 0: 1280x800x32@0

While this may look perfectly fine, the original resolution was 1280x800 with HIDPI, and after the set command, the resolution changed to 1280x800 without HIDPI.

I have some coding experience, and access to such a macbook, so with a little guidance I can probably help in developing / testing any changes.

Logging

At mozilla, we will be running this program in an automated way. It'd be helpful to have logging output to help check for errors.

Command "set" not working on latest MacBook Pro 16"

On latest MacBook Pro 16" (running Catalina) list works fine but running set with any of the available resolutions doesn't have any effect. Any ideas what the issues could be or how this could be fixed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.