Coder Social home page Coder Social logo

univ-of-utah-marriott-library-apple / display_manager Goto Github PK

View Code? Open in Web Editor NEW
234.0 15.0 19.0 71.33 MB

An open-source Python library which can modify your Mac's display settings manually or automatically.

License: MIT License

Python 100.00%
mac macadmin macadmins python pyobjc brightness mirroring pyobjc-bindings display-manager orientation

display_manager's Introduction

Display Manager

An open-source Python library which can modify your Mac's display settings.

Includes the library itself, and a command-line API + GUI to use it in pre-specified ways.

Contents

Download

The latest release is available for download here.

Contact

If you have any comments, questions, or concerns, feel free to send us an email.

System Requirements

Display Manager only runs on Mac computers. It depends on the Apple-supplied Python 2.7 binary, which lives at /usr/bin/python and comes pre-configured with the PyObjC bindings. These bindings allow Python to access the Objective-C methods that perform display manipulations.

If you have replaced the setDefault /usr/bin/python binary (which is not generally advised), you should ensure that it has the PyObjC bindings set up correctly.

Note: Display Manager has only been tested on El Capitan (10.11), Sierra (10.12), High Sierra (10.13), and Mojave Beta (10.14). If you experience issues on other versions of macOS, please let us know.

Purpose

Display Manager programmatically manages Mac displays, including display resolution, refresh rate, rotation, brightness, screen mirroring, and HDMI underscan. Its primary intended purpose is to allow system administrators and developers to automatically configure any number of Mac displays, by use of the command-line scripts and the Display Manager Python library.

Several intended use-cases for Display Manager are elaborated in usage examples.

Limitations

Currently, Display Manager has a few important limitations that are worth noting:

  • Must be currently logged in as the user of the current Aqua Session to use Display Manager (and in cases when there is no such user (e.g. the login screen), Display Manager cannot be used).

Recommended workarounds:

  • Transfer CoreGraphics control to the desired user via $ sudo /System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession -switchToUserID <UID>, where <UID> is the user ID of the desired user.
  • Switch to the user of the current Aqua Session via $ su <user>, where <user> is the user of the current Aqua Session.
  • Simply configure displays during login/logout, or while logged in. Settings persist after logout, so whichever configurations you set during logout will remain active at the login screen.

Get Started

First, check that your system satisfies the requirements in System Requirements. If you haven't touched /usr/bin/python, it should.

Next, download the latest installer here. Included within are two files: Display Manager.pkg, and Uninstall Display Manager.pkg. To install, click the former and follow the prompts on-screen; to uninstall, do the same for the latter.

For the curious: Display Manager.pkg puts the Display Manager library in /Library/Python/2.7/site-packages/, and the command-line interface in /usr/local/bin. (Note: currently, if you wish to use the GUI, you must manually run gui.py from the command line. Standalone app in /Applications coming in a future version.)

Next, see Overview for an idea of what you can do with Display Manager.

Overview

The Display Manager suite comes in 3 parts: the Display Manager library (display_manager_lib.py), the command-line API (display_manager.py), and the GUI (gui.py).

Library

The Display Manager library is housed in display_manager_lib.py, which contains the following:

  • Classes:

    • The Display class is a virtual representation of a connected physical display. It allows one to check the status of various display parameters (e.g. brightness, resolution, rotation, etc.) and to configure such parameters.
    • The DisplayMode class is a simple representation of Quartz's Display Modes. DisplayModes can be sorted, converted to strings, and passed as parameters to various methods which configure the display.
  • Functions:

    • getMainDisplay returns the primary Display;
    • getAllDisplays returns a Display for each connected display
    • getIOKit allows one to manually access the IOKit functions and constants used in Display Manager (usage not recommended -- it's much simpler to go through Displays instead, if possible)

Command-Line API

The command-line API, accessed via display_manager.py, allows you to manually set display resolution, refresh rate, brightness, rotation, screen mirroring, and HDMI underscan. See command-line usage below for more information.

GUI

First, set the display you'd like to configure the settings for in the displays dropdown menu. Any time you select a display, all of the other menus automatically switch to that display's current settings, but you can refresh them manually by clicking the "refresh" button.

display dropdown

Next, select the display settings you'd like from the other menus. Note that the brightness, rotation, and underscan sliders default to 0 and cannot be changed if your display does not allow us to access them.

brightness, rotation, and underscan sliders

To configure screen mirroring, select the display you'd like to mirror, and choose whether to enable or disable it.

mirroring menu

Finally, select either "Set Display" or "Build Script". If you click "Set Display", the display will be configured to the settings you've selected. If you pick "Build Script", you'll be given a file dialog to save a script which sets your display to these settings automatically whenever run (using the commands seen in display_manager.py).

set and build buttons

Command-Line Usage

The Display Manager command-line API supports the following commands:

$ display_manager.py [command]

For more information on each command, see its section below:

Help

Use help to see help documentation for any command.

Usage: $ display_manager.py help <command>

Commands Description
help Show help information about a command
show Show current/available display configurations
res Manage the display resolution
brightness Manage display brightness
rotate Manage display rotation
underscan Manage display underscan
mirror Manage screen mirroring

Examples

  • Show help information for the res command:

$ display_manager.py help res

  • Show general help information to see which commands are available:

$ display_manager.py help

Show

Use show to learn more about the supported display configurations for your hardware.

Usage: $ display_manager.py show [subcommand] [options] [scope...]

Subcommands (optional) Description
current (default) Show the current display configuration
default Apple's recommended default configuration
highest Show the highest available configuration
available Show a list of all the available configurations
Options (optional; only applies to available) Description
no-hidpi Don't show HiDPI resolutions
only-hidpi Only show HiDPI resolutions

Notes:

  • "HiDPI" , also known as "Retina Display" among Apple products, refers to a high ratio of pixels (or "dots" in "dots per inch"/"DPI") to the physical area they occupy in a display. Fore more information, see here
  • By default, both HiDPI and non-HiDPI resolutions are shown.
Scope (optional) Description
main Perform this command on the main display
ext<N> Perform this command on external display number N (starting at 0)
all (default) Perform this command on all connected displays

Examples

  • Show all displays' current configurations:

$ display_manager.py show or $ display_manager.py show all

  • Show the main display's default configuration:

$ display_manager.py show default main

  • Show the highest configuration for the first external display:

$ display_manager.py show highest ext0

  • Show all available HiDPI configurations for all displays:

$ display_manager.py show available only-hidpi or $ display_manager.py show available only-hidpi all

Res

Use res to modify display resolution and refresh rate. (Checking desired configuration through show beforehand is recommended.)

usage: $ display_manager.py res <resolution> [refresh] [options] [scope...]

Resolution Description
default Apple's recommended default configuration
highest Set the display to the highest available configuration
<width> <height> Width and height (in pixels)

Note: width and height must be separated by at least one space.

Refresh (not used by "default" or "highest" resolution; optional otherwise) Description
<refresh> Refresh rate (in Hz)

Note: if refresh rate is not specified, it will default to whichever rate is available at the desired resolution.

Options (optional) Description
no-hidpi Don't set to HiDPI configurations
only-hidpi Only set to HiDPI configurations

Notes:

  • "HiDPI" , also known as "Retina Display" among Apple products, refers to a high ratio of pixels (or "dots" in "dots per inch"/"DPI") to the physical area they occupy in a display. Fore more information, see here.
  • By default, both HiDPI and non-HiDPI resolutions are shown.
SCOPE (optional) Details
main (default) Perform this command on the main display
ext<N> Perform this command on external display number N (starting at 0)
all Perform this command on all connected displays

Examples

  • Set the main display to 1920x1080:

$ display_manager.py res 1920 1080 or $ display_manager.py res 1920 1080 main

  • Set all displays to their default configurations:

$ display_manager.py res default all

  • Set the first external display to its highest available configuration:

$ display_manager.py res highest ext0

  • Set the first two external displays to 1024x768 at 60Hz:

$ display_manager.py res 1024 768 60 ext0 ext1

Rotate

Use rotate to change your display's orientation.

usage: $ display_manager.py rotate <angle> [scope...]

Angle Description
<angle> Desired display rotation; must be a multiple of 90
Scope (optional) Description
main (default) Perform this command on the main display
ext<N> Perform this command on external display number N (starting at 0)
all Perform this command on all connected displays

Examples

  • Rotate the main display by 90 degrees (counter-clockwise):

$ display_manager.py rotate 90 or $ display_manager.py rotate 90 main

  • Return all displays to default orientation:

$ display_manager.py rotate 0 all

Brightness

Use brightness to set the brightness on your display.

usage: $ display_manager.py brightness <brightness> [scope...]

Brightness Description
<brightness> A number between 0 and 1 (inclusive); 0 is minimum brightness, and 1 is maximum brightness
Scope (optional) Description
main (default) Perform this command on the main display
ext<N> Perform this command on external display number N (starting at 0)
all Perform this command on all connected displays

Examples

  • Set the brightness of the main display to 40% of its maximum brightness:

$ display_manager.py brightness .4 or $ display_manager.py brightness .4 main

  • Set the brightness of all displays to their maximum:

$ display_manager.py brightness 1 all

Note: many displays do not support setting brightness automatically; this is most often the case with external monitors. If Display Manager cannot configure your display's brightness, see whether it can be set manually on the display's hardware.

Underscan

Use underscan to configure HDMI underscan settings.

usage: $ display_manager.py underscan <underscan> [scope...]

Underscan Description
<underscan> A number between 0 and 1 (inclusive); 0 is minimum underscan, and 1 is maximum underscan
Scope (optional) Description
main (default) Perform this command on the main display
ext<N> Perform this command on external display number N (starting at 0)
all Perform this command on all connected displays

Notes:

  • HDMI underscan settings can fix displays that under-render images, causing the outer edge of the screen to be left empty. Displays default to underscan 0. For more details, see here.
  • Display Manager can only set underscan on HDMI screens, and not all HDMI screens are supported. If Display Manager cannot configure your display's underscan, see whether it can be set manually on the display's hardware.

Examples

  • Set main display to 0% underscan:

$ display_manager.py underscan 0 or $ display_manager.py underscan 0 main

  • Set all displays to 75% underscan:

$ display_manager.py underscan .75 all

Mirror

Use mirror to enable or disable display mirroring.

usage:

  • $ display_manager.py mirror enable <source> <target...>
  • $ display_manager.py mirror disable [scope...]
Subcommands Description
enable Set <target>s to mirror <source>
disable Disable mirroring on <scope>s
Source/Target(s) (not used by disable) Description
source The display which will be mirrored by the targets; must be a single element of scope (see below); cannot be all
target(s) The display(s) which will mirror the source; must be an element of scope (see below)
Scope Description
main The main display
ext<N> External display number N (starting at 0)
all (default scope for disable) For enable: all connected displays besides source (only available to target); for disable: all connected displays

Note: if main is set to mirror another display, that display becomes main.

Examples

  • Set all external displays to mirror the main display:

$ display_manager.py mirror enable main all

  • Set the main display and the first external display to mirror the second external display:

$ display_manager.py mirror enable ext1 main ext0

  • Stop mirroring on all displays:

$ display_manager.py mirror disable

  • Stop mirroring on the main display:

$ display_manager.py mirror disable main

Usage Examples

Display Manager allows you to manipulate displays in a variety of ways. You can write your own Python scripts with the Display Manager library, write shell scripts or manually configure displays using the command-line API, or access the functionality of the command-line API through the GUI. A few potential use cases are outlined below:

Library Examples

First, import the Display Manager library, like so:

import display_manager_lib as dm

Next, say you'd like to automatically set all the displays connected to your computer to their highest resolution. A simple script might look like this:

for display in dm.getAllDisplays():
    display.setMode(display.highestMode())

Perhaps you'd like your main display to rotate to 90 degrees. The following would work:

display = dm.getMainDisplay()
display.setRotate(90)

Finally, consider a case where you'd like the main display in a set of two displays to mirror each other if not mirroring, or to disable mirroring if it is currently enabled. You might try this:

main = dm.getMainDisplay()
ext0 = [d for d in dm.getAllDisplays() if d.tag == "ext0"][0]
if not ext0.mirrorSource:
    ext0.setMirrorSource(main)
else:
    ext0.setMirrorSource(None)

You can use any of the properties and methods of Display objects to configure their settings, which is exactly how the command-line API works. For more information about the Display Manager Library, see here, or look at the triple-quoted docstrings in display_manager_lib.py for any object or function you're interested in.

Command-Line Examples

In many cases, it may be desirable to configure displays from the command line, whether manually or via a script. Say you'd like a script to automatically set a display to its highest available resolution. The following would do just that:

$ display_manager.py res highest

But, in many cases, you might want to call several such commands at the same time. Of course, you may write them out line-by-line, but this takes a little longer, and more importantly, running several commands in this way may lead to undesired interference between commands. As such, it is recommended that multiple commands be run like so:

$ display_manager.py res 1920 1080 rotate 90 brightness .5 ...

In this way, you may pass in as many commands as you like, and Display Manager will find a way to run them simultaneously without encountering configuration errors.

Note: only one help command may be run at a time, but any number of other commands may be run simultaneously in a non-blocking fashion.

System Administration Examples

Jamf Pro

"Jamf Pro, developed by Jamf, is a comprehensive management system for Apple macOS computers and iOS devices... [including] deploying and maintaining software, responding to security threats, distributing settings, and analyzing inventory data." source

Suppose you'd like all computers in a particular Jamf Pro scope to default to their highest "retina-friendly" resolution at maximum brightness at login. You could create a policy

example Jamf policy

and add a script containing the following to it

#!/bin/sh

# Check to make sure the library and command-line API are both installed
if [[ -e /Library/Python/2.7/site-packages/display_manager_lib.py && \
	-e /usr/local/bin/display_manager.py ]] ; then
	
	display_manager.py res highest only-hidpi brightness 1

else
	exit 1
fi

like so:

example Jamf script

For more details about command-line usage, see here; for examples, see command-line examples.

Outset

"Outset is a script which automatically processes packages, profiles, and scripts during the boot sequence, user login, or on demand." source

Perhaps you're managing several HDMI displays via Outset, and you'd like them to automatically rotate to portrait mode and set underscan to 50%. You could save the following script to /usr/local/outset/login-every/flip.sh:

#!/bin/sh

# Check to make sure the library and command-line API are both installed
if [[ -e /Library/Python/2.7/site-packages/display_manager_lib.py && \
	-e /usr/local/bin/display_manager.py ]] ; then
	
	display_manager.py rotate 90 underscan .5
	
else
	exit 1
fi

For more details about command-line usage, see here; for examples, see command-line examples.

Update History

Date Version Update
2018-08-20 1.0.1 Fixed minor compatibility issues with macOS 10.14 Beta.
2018-07-13 1.0.0 First edition of full Display Manager. Created the DisplayManager library, the new command-line API, and the GUI; added the ability to run multiple commands at once; added rotation and HDMI underscan features.
2015-10-28 0.1.0 Legacy iteration of Display Manager. Created command-line API.
2019-05-17 1.0.2 Fixed an issue that would cause crash Display Manager when retrieving DisplayModes on certain monitors

display_manager's People

Contributors

ahdavies6 avatar frizlab avatar pdarragh avatar sambarufus avatar shuntagami avatar uurazzle 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

display_manager's Issues

Problem with color depth on UHD 630

When I use Display Manager to set a resolution and refresh rate, it will change the colour depth to 24 bits. When I use System Preferences to set the resolution, 30 bit is used as the UHD 630 in my machine, where the screen is connected to, can’t provide 32-bit.

In your answer to issue 6 you explain that color depth has been deprecated as almost all modern monitors use 32-bit colour depths. As far as my monitors are concerned that is true. But the latest low-end Mac models come with a UHD 630 only providing 24-, 30- (not for HDMI), and 36-bit colour depth (see here).

Therefore, is it possible to re-implement setting of the colour depth? Or at least have Display Manager set the highest possible depth if the GPU is not capable of 32-bit?

Cannot change the brightness of main display

def setBrightness(self, brightness):
    """
    :param brightness: The desired brightness, from 0 to 1.
    """
    error = iokit["IODisplaySetFloatParameter"](self.__servicePort, 0, iokit["kDisplayBrightness"], brightness)
    if error:
        if self.isMain:
            raise DisplayError("Cannot manage brightness on display \"{}\"".format(self.tag))
        else:
            raise DisplayError(
                "Display \"{}\"\'s brightness cannot be set.\n"
                "External displays may not be compatible with Display Manager. "
                "Try setting manually on device hardware.".format(self.tag))

I wanted to use this code for my project as I am unable to find a way to change the macos brightness from python and this library is one caught my eye but it clearly doesnt support changing main display brightness , or I am just understanding it wrong.

warnings.warn("Error parsing BridgeSupport data

Running display_manager.py show on my Mac (running 10.14 (18A365a)) gives this warning:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/_bridgesupport.py:674: RuntimeWarning: Error parsing BridgeSupport data for IOKit: PyObjCRT_SkipTypeSpec: Unhandled type '0'
warnings.warn("Error parsing BridgeSupport data for %s: %s" % (frameworkName, e), RuntimeWarning)

before it outputs the expected information:

display "main":
resolution:     1440x900
refresh rate:   0
HiDPI:          True
rotation:       0
brightness:     1.00

Similarly display_manager.py help gives this warning:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/_bridgesupport.py:674: RuntimeWarning: Error parsing BridgeSupport data for IOKit: PyObjCRT_SkipTypeSpec: Unhandled type '0'
warnings.warn("Error parsing BridgeSupport data for %s: %s" % (frameworkName, e), RuntimeWarning)

before showing the expected

usage:  display_manager.py <command>

COMMANDS (required)
    help        Show help information about a command
    show        Show current/available display configurations
    res         Manage display resolution
    brightness  Manage display brightness
    rotate      Manage display rotation
    underscan   Manage display underscan
    mirror      Manage screen mirroring

Recommendation: add a 'version' arg

display_manager.py version should (IMO) show 1.0.1 or whatever is in the code as # Display Manager, version XYZ where XYZ is the version info.

MBP16 and Philips 49" certain modes cause exception

Hi,

I am using two resolutions on my 49" (Philips 499P9) screen mainly and skip from "fullscreen" 5120x1440 to "split screen" 2560x1440 for two connected computers. Manual selection works on control panel or with other tools, but I'd like to use a script to switch even faster.

Unfortunately display_manager doesn't let me change resolution/refresh to my prefered values:

/usr/local/bin/display_manager.py res 5120 1440 30 ext0
/usr/local/bin/display_manager.py:281: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  raise CommandExecutionError(e.message, command=self)
Error: Display "ext0" cannot be set to 5120x1440
/usr/local/bin/display_manager.py res 2560 1440 60 ext0
/usr/local/bin/display_manager.py:281: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  raise CommandExecutionError(e.message, command=self)
Error: Display "ext0" cannot be set to 2560x1440

However, the following setting do change screen resolution for example without any issue.

/usr/local/bin/display_manager.py res 3840 1080 60 ext0
/usr/local/bin/display_manager.py res 3840 1080 30 ext0
/usr/local/bin/display_manager.py res 1920 1080 60 ext0

Any idea to override or force the settings for 5120x1440@30Hz and 2560x1440@60Hz and get around the exception?

Thanks in advance
Markus

10.7.5 : ValueError: cftype for 'IOBlitMemoryRef' must include gettypeid_func, tollfree or both

Hi !

I'm trying to execute display_manager on a 10.7.5 Mac Pro.
DisplayManager-1.0.2.dmg has been installed successfully, but any command I type results in:

Mac-Pro-de-crapulette:display_manager kalou$ ./display_manager.py res
Traceback (most recent call last):
File "./display_manager.py", line 1257, in
main()
File "./display_manager.py", line 1240, in main
Command(verb="help", subcommand=e.verb).run()
File "./display_manager.py", line 136, in init
getIOKit()
File "/Users/kalou/display_manager/display_manager_lib.py", line 680, in getIOKit
globals=globals()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/_bridgesupport.py", line 140, in initFrameworkWrapper
_parseBridgeSupport(data, globals, frameworkName, dylib_path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/_bridgesupport.py", line 42, in _parseBridgeSupport
objc.parseBridgeSupport(data, globals, frameworkName, *args, **kwds)
ValueError: cftype for 'IOBlitMemoryRef' must include gettypeid_func, tollfree or both

Any clue of what's going on ?

Setting the primary display

Thank you so much for this! It's really helped with an issue we've been having in one of our computer labs - the professor wanted mirroring disabled when a user logs in, so deploying this alongside a script run with outset seemed to do the trick.

Unfortunately, running this command at login:

/usr/local/bin/display_manager.py mirroring disable

has the side effect of making the wrong monitor the primary display - the Mac is connected to a TV, and the TV is always set as the primary display. Is there a way to override that with Display Manager? I tried a few command combinations but none of them would change this - for example, set highest turns off mirroring, bumps up the resolution of each display, but leaves the (wrong) primary display intact.

If it's not something Display Manager supports, but you know of a different way to script this, I'd really appreciate it. Thanks!

Mike

Unable to 'get', 'show' or 'query' current brightness

First off - awesome tool! I picked up on this while looking to set the 'optimise for:' option (in the Displays System Preference) via script.

More of a feature request - I currently get & set the brightness of displays with other scripts. Is display_manager going to be able to query & report the current brightness of a given display in the future?

GUI command

Hello,
Im nooby with Python but I can't launch gui.py (usr/local/bin/gui.py) from command line :
Traceback (most recent call last):
File "./gui.py", line 454, in
main()
File "./gui.py", line 450, in main
view.start()
File "./gui.py", line 443, in start
self.__reloadDisplay()
File "./gui.py", line 430, in __reloadDisplay
self.__modeSelectionInit()
File "./gui.py", line 226, in __modeSelectionInit
for mode in sorted(self.display.allModes(), reverse=True):
TypeError: 'list' object is not callable

KeyError raised when running `display_manager.py show available`

This issue is submitted on behalf of Rob:

First, thanks for creating Display Manager!

I’ve been using v1.0.1 successfully for some time, with a trio of different displays (including a MacBook Pro 15-inch’s internal display). No errors, no problems. Today, I connected up a Dell P2415Q, which is the first Retina-type external display I’ve tried. With it attached, various Display Manager commands result in traceback errors, which I’ve never gotten before with your software.

$ display_manager.py show available
display "main":
Traceback (most recent call last):
  File "/usr/local/bin/display_manager.py", line 1257, in <module>
    main()
  File "/usr/local/bin/display_manager.py", line 1250, in main
    commands.run()
  File "/usr/local/bin/display_manager.py", line 671, in run
    command.run()
  File "/usr/local/bin/display_manager.py", line 269, in run
    self.__handleShow()
  File "/usr/local/bin/display_manager.py", line 449, in __handleShow
    for mode in sorted(display.allModes, reverse=True):
  File "/Library/Python/2.7/site-packages/display_manager_lib.py", line 291, in allModes
    uniqueModes.remove(mode)
KeyError: <display_manager_lib.DisplayMode object at 0x1116c6ed0>

Best way to use this code in a separate module

Hi! Thank you so much for your work and for sharing it!

I am working on a new module aimed to get info and control monitors (specially in multi-monitor setups). You can check it here if you are curious. Struggling with macOS I found your module very useful but, since it is not available on PyPi (I already read in a reply of yours that it is not planned), I was wondering the best way to integrate it into my own module. I just need the rotation and brightness functions (no way to also deal with contrast and scale, there is?), but I felt that I had to ask before just copy-pasting the related code or the display_manager_lib.py file (of course, adding the license in all cases).

Thanks in advance!

Blank response for "show"

I'm not sure what's causing this. I'm running macOS Catalina. When I run the "show" command I get nothing.

% ./display_manager.py show
%

Thoughts?

Output error

I use simple script for get current brightness level.

import display_manager.display_manager_lib
import Quartz
print(display_manager.display_manager_lib.Display(displayID=Quartz.CGMainDisplayID()).brightness)

Output is:

(-536870201, 0.0)

My environment

MacOS Monterey 13.1

python 3.11

How to solve this problem?

Assertion error at getIOKit method

Hi!

I recently managed to test in an actual macOS (I was testing in a macOS VM, in which many features, including your module, was not working).

I am running this on mac mini with Catalina (10.15.7) and Python 3.8.2 (let me know if you need other details)

When executing this:

import Quartz

from ._display_manager_lib import Display  # display_manager_lib.py is directly taken from your repo, and not modified at all

self.handle = Quartz.CGMainDisplayID()
self._dm = Display(self.handle)

I receive this error:

2023-10-16 21:26:19.022 Python[502:4685] *** Assertion failure in +[UINSServiceViewController initialize], /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/ViewBridge/ViewBridge-468/UINSServiceViewController.m:203

The origin of this error is within getIOKit() function, but all its content is totally alien to me, sorry. There is no error if you just comment getIOKit() in Display's class __init__() method, but rationally all related functions do not work.

If, in addition, I run this:

self._dm.brightness()      # returns None
self._dm.setBrightness(50)  # This crashes (see below)

I get this error:

Traceback (most recent call last):
    File "test.py", line 12, in <module>
        mon1.setBrightness(50)
    File "/Users/Angel/Library/Python/3.8/lib/python/site-packages/pymonctl/_pymonctl_macos.py", line 320, in setBrightness
        self._dm.setBrightness(brightness)
    File "/Users/Angel/Library/Python/3.8/lib/python/site-packages/pymonctl/_display_manager_lib.py", line 449, in setBrightness
        raise DisplayError("Cannot manage brightness on display \"{}\"".format(self.tag))
pymonctl._display_manager_lib.DisplayError: Cannot manage brightness on display "main"

I know I'm using your module in a non-standard way but, if you can bring some light to this problem, I would really appreciate it!

Feature Request: Incorporate customdisplayprofiles

It would be fantastic if you could incorporate Tim Sutton's customdisplayprofiles command line tool into display_manager, which would make this a complete solution for controlling colour-calibrated Macs (i.e. iMacs and other displays where you can't lock down the controls). Tim is no longer working in the job that led him to write his tool, so it will also need a new home under Python 3. Your tool seems to be the perfect complement to it, so it might be useful to include its functionality when you rewrite display_manager for Python 3 (see issue #19). Again, I can help test.

“DisplayManager-1.0.2.pkg” can’t be opened because Apple cannot check it for malicious software.

When I try to open the .pkg I get this error:

Text of screenshot is below:

“DisplayManager-1.0.2.pkg” can’t be opened because Apple cannot check it for malicious software.

This software needs to be updated. Contact the developer for more information.

Safari downloaded this file today at 5:00 PM from github-production-release-asset-2e65be.s3.amazonaws.com.

ProductName:	Mac OS X
ProductVersion:	10.14.5
BuildVersion:	18F132

Implementing pip

Very useful open source project!

I am a privacy and security researcher and YouTuber.

I was desperate to find an open source way to configure DisplayPort output to non-high-dpi 1080P resolution (to lower CPU load when recording screen using Kap).

Any chance project can be adapted so library and command line utility can be install it using pip?

I know little about Python so question might be naive.

Can't mirror to all external displays

I'm getting the following error when executing display_manager.py mirror enable main all

Traceback (most recent call last):
File "/usr/local/bin/display_manager.py", line 1257, in
main()
File "/usr/local/bin/display_manager.py", line 1250, in main
commands.run()
File "/usr/local/bin/display_manager.py", line 682, in run
currentMirror = display.mirrorSource
AttributeError: 'list' object has no attribute 'mirrorSource'

I can mirror to individual external displays.

macbook pro 15" : Display "main" cannot be set to 1440x900

Display_Manager v.1.0.1. / macOS 10.12.6 / macbook pro 8,2

After restore the macbook from a Timemachine Backup the screen resolution 1440 x 900 only was set and available with no external monitor connected. As soon the external screen got plugged-in the main macbook LCD resolution jumped to the not-scaled 1440 x 852 – though this screen was successfully set to 1440 x 900 before the system restore.

When I now try to set resolution with plugged in external monitor Display Manager gives this result:

xxx:~ xxx$ display_manager.py res 1440 900 main
/usr/local/bin/display_manager.py:281: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  raise CommandExecutionError(e.message, command=self)
Error: Display "main" cannot be set to 1440x900

(whereas i was able to set the wanted 1440 x 900 with the tool SwitchRes (v.4.8.1)

Python 2 EOL

While Python 2.7 is still available in macOS, it is no longer being updated as of April 2020. For continued use, this tool will need to be rewritten for Python 3. (The use of Greg Neagle's Relocatable Python may be useful for final deployment.) I do not have the coding skills to write it, but would be willing to help test.

Error -536870201

I use simple script for get current brightness level.

Import display_manager.display_manager_lib
import Quartz
print(display_manager.display_manager_lib.Display(displayID=Quartz.CGMainDisplayID()).brightness)

Output is:

(-536870201, 0.0)

My environment

MacOS Monterey 13.1
python 3.11

How to solve this problem?

Command to set the equivalent of a "scaled" resolution?

Hello,

display_manager looks great! I'm on macOS Catalina. I was just wondering if there is an easy way to set the "scaled" resolution for slightly larger text, as shown in the following screenshot:

I think it would be really useful if some of these "Scaled" examples could be added to the README. I'm trying to automate my Mac setup with a script, and I prefer this scaled resolution.

Thanks!

Underscan not working

I ran the following command to see a list of my displays

$ display_manager.py show

display "main":
resolution:     2560x1440
refresh rate:   0
HiDPI:          True
rotation:       0
brightness:     0.84
underscan:      0.00

display "ext0":
resolution:     1080x1920
refresh rate:   60
HiDPI:          False
rotation:       90
underscan:      1.00

Then I ran this command to underscan the external display

display_manager.py underscan 0.7 ext0

It gave me no error, so I assumed everything worked okay. After running that command, I restarted my computer and low and behold, the underscan stayed exactly the same... Am I doing something wrong???

OUTPUT of show exactly the same

$ display_manager.py show

display "main":
resolution:     2560x1440
refresh rate:   0
HiDPI:          True
rotation:       0
brightness:     0.84
underscan:      0.00

display "ext0":
resolution:     1080x1920
refresh rate:   60
HiDPI:          False
rotation:       90
underscan:      1.00

What happened to `set` and `show exact`?

I had some scripts that were using display_manager.py show exact and display_manager.py set closest and they no longer seem to work. In fact, they no longer seem to exist at all.

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.