[GH-ISSUE #27] Automatically adjust external display based on internal display + Touch Bar support #27

Closed
opened 2026-05-05 04:45:37 -06:00 by gitea-mirror · 20 comments
Owner

Originally created by @funbben on GitHub (Apr 13, 2018).
Original GitHub issue: https://github.com/MonitorControl/MonitorControl/issues/27

Originally assigned to: @waydabber on GitHub.

It would be nice to be able to use the mac "auto adjust brightness" to set the brightness of external display automatically

https://i.stack.imgur.com/eYQuM.png

Originally created by @funbben on GitHub (Apr 13, 2018). Original GitHub issue: https://github.com/MonitorControl/MonitorControl/issues/27 Originally assigned to: @waydabber on GitHub. It would be nice to be able to use the mac "auto adjust brightness" to set the brightness of external display automatically https://i.stack.imgur.com/eYQuM.png
gitea-mirror 2026-05-05 04:45:37 -06:00
Author
Owner

@the0neyouseek commented on GitHub (Apr 14, 2018):

Hi @funbben,

Thats a great idea but would be quite difficult to implement because this feature depends on the ambient light sensor (located next to the camera) of your Macbook Pro/iMac and not all external screen have one.

I'll leave this issue open for now to see if anyone has a better idea about tackling this.

PS. We could, for exemple use the one present on your MBP/iMac if we have one, but I'm not sure how. I'll look into it.

<!-- gh-comment-id:381317580 --> @the0neyouseek commented on GitHub (Apr 14, 2018): Hi @funbben, Thats a great idea but would be quite difficult to implement because this feature depends on the ambient light sensor (located next to the camera) of your Macbook Pro/iMac and not all external screen have one. I'll leave this issue open for now to see if anyone has a better idea about tackling this. PS. We could, for exemple use the one present on your MBP/iMac if we have one, but I'm not sure how. I'll look into it.
Author
Owner

@funbben commented on GitHub (Apr 14, 2018):

The idea was to use mac internal sensor and apply same setting as Mac display

<!-- gh-comment-id:381362854 --> @funbben commented on GitHub (Apr 14, 2018): The idea was to use mac internal sensor and apply same setting as Mac display
Author
Owner

@retrography commented on GitHub (Jun 18, 2018):

I think the idea @funbben described is actually very interesting. The only thing is: One will have to check first whether the computer is a laptop and whether it is running the clamshell mode or not.

<!-- gh-comment-id:397995103 --> @retrography commented on GitHub (Jun 18, 2018): I think the idea @funbben described is actually very interesting. The only thing is: One will have to check first whether the computer is a laptop and whether it is running the clamshell mode or not.
Author
Owner

@rowanalex123 commented on GitHub (Jul 18, 2018):

Hammerspoon provides the lux reading from the ambient light sensor on Macs. Apprently they use the raw value from the sensor and run Mozilla's algorithm to convert it to lux

<!-- gh-comment-id:405913882 --> @rowanalex123 commented on GitHub (Jul 18, 2018): Hammerspoon provides the lux reading from the ambient light sensor on Macs. Apprently they use the raw value from the sensor and run Mozilla's algorithm to convert it to lux
Author
Owner

@retrography commented on GitHub (Jul 18, 2018):

@rowanalex123 Have you actually tried that? The function only returns an error for me -- which is a -1 (on MacBook Pro 2016).

<!-- gh-comment-id:405962101 --> @retrography commented on GitHub (Jul 18, 2018): @rowanalex123 Have you actually tried that? The function only returns an error for me -- which is a -1 (on MacBook Pro 2016).
Author
Owner

@rowanalex123 commented on GitHub (Jul 19, 2018):

I tried it now. It returns -1 for me as well on a 2017 Mac pro

<!-- gh-comment-id:406285163 --> @rowanalex123 commented on GitHub (Jul 19, 2018): I tried it now. It returns -1 for me as well on a 2017 Mac pro
Author
Owner

@arnoappenzeller commented on GitHub (Jan 8, 2019):

I would really like this idea with using the Mac Books ambient sensor.

Has someone already tried this code for reading the data?

I think I'm gonna play around a bit with it soon

<!-- gh-comment-id:452307822 --> @arnoappenzeller commented on GitHub (Jan 8, 2019): I would really like this idea with using the Mac Books ambient sensor. Has someone already tried [this code](https://gist.github.com/phillbaker/4099814) for reading the data? I think I'm gonna play around a bit with it soon
Author
Owner

@the0neyouseek commented on GitHub (Jan 10, 2019):

Hi, first of all sorry for the late response.
I'll try to work on this feature this week-end.

<!-- gh-comment-id:453244923 --> @the0neyouseek commented on GitHub (Jan 10, 2019): Hi, first of all sorry for the late response. I'll try to work on this feature this week-end.
Author
Owner

@jcastro commented on GitHub (Aug 30, 2019):

Just something that might be of interest. The new LG 2019 Ultrafine 5k is finally using the light sensor (see https://twitter.com/jonatan/status/1167163794281455616) so maybe there's a chance to use that information to automatically change others' display brightness (probably with a configurable offset for the value)

<!-- gh-comment-id:526780031 --> @jcastro commented on GitHub (Aug 30, 2019): Just something that might be of interest. The new LG 2019 Ultrafine 5k is finally using the light sensor (see https://twitter.com/jonatan/status/1167163794281455616) so maybe there's a chance to use that information to automatically change others' display brightness (probably with a configurable offset for the value)
Author
Owner

@jcastro commented on GitHub (Oct 14, 2019):

Another interesting fact, looks like now even the older LG Ultrafine 5k that didn't have the auto-brightness working now it's enabled if you are on Catalina.

<!-- gh-comment-id:541594232 --> @jcastro commented on GitHub (Oct 14, 2019): Another interesting fact, looks like now even the older LG Ultrafine 5k that didn't have the auto-brightness working now it's enabled if you are on Catalina.
Author
Owner

@rshev commented on GitHub (May 4, 2020):

Just found this app, mainly because I'd like to have different brightness during the day and in the evenings, and immediately thought of this idea. Has anyone had any luck reading ambient light values? I might help, I do swift for a living.

<!-- gh-comment-id:623411462 --> @rshev commented on GitHub (May 4, 2020): Just found this app, mainly because I'd like to have different brightness during the day and in the evenings, and immediately thought of this idea. Has anyone had any luck reading ambient light values? I might help, I do swift for a living.
Author
Owner

@dmatora commented on GitHub (Jul 3, 2020):

@the0neyouseek

  1. There is an open source console app that allows automatically changing brightness on old UltraFine 4K/5K monitors that don't have ambient light support built into maOS.
    https://github.com/qvacua/ultrafine-auto-brightness
    I own old UltraFine 4K monitor and would love to see it's ambient light sensor support in MonitorControl

  2. It would also be awesome to trigger dark theme based on ambient light sensor value, like this (not very user friendly) open source app does http://codes.kary.us/health/starlight

  3. And finally there is an open source app that allows to use Macbook sensor to adjust brightness of external monitor https://github.com/OCJvanDijk/Brightness-Sync it's code can be used for those who use regular monitors with no ambient light sensor

<!-- gh-comment-id:653646237 --> @dmatora commented on GitHub (Jul 3, 2020): @the0neyouseek 1. There is an open source console app that allows automatically changing brightness on old UltraFine 4K/5K monitors that don't have ambient light support built into maOS. https://github.com/qvacua/ultrafine-auto-brightness I own old UltraFine 4K monitor and would love to see it's ambient light sensor support in MonitorControl 2. It would also be awesome to trigger dark theme based on ambient light sensor value, like this (not very user friendly) open source app does http://codes.kary.us/health/starlight 3. And finally there is an open source app that allows to use Macbook sensor to adjust brightness of external monitor https://github.com/OCJvanDijk/Brightness-Sync it's code can be used for those who use regular monitors with no ambient light sensor
Author
Owner

@stale[bot] commented on GitHub (Aug 3, 2021):

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

<!-- gh-comment-id:892141372 --> @stale[bot] commented on GitHub (Aug 3, 2021): Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require attention? This issue may be closed if no further activity occurs. Thank you for your contributions.
Author
Owner

@sraka1 commented on GitHub (Aug 6, 2021):

Feature request is still pending. Commenting so it's not auto-closed.

<!-- gh-comment-id:894331502 --> @sraka1 commented on GitHub (Aug 6, 2021): Feature request is still pending. Commenting so it's not auto-closed.
Author
Owner

@waydabber commented on GitHub (Aug 20, 2021):

This might be a bit out of focus for MonitorControl right now but still we might add this function in the future as apparently this is among the core ideas all the way back to 2018. :)

There is an app called Lunar however made by @alin23 that already does this thing for those who are impatient for a solution.

<!-- gh-comment-id:902958346 --> @waydabber commented on GitHub (Aug 20, 2021): This might be a bit out of focus for MonitorControl right now but still we might add this function in the future as apparently this is among the core ideas all the way back to 2018. :) There is an app called [Lunar](https://lunar.fyi) however made by @alin23 that already does this thing for those who are impatient for a solution.
Author
Owner

@alin23 commented on GitHub (Aug 20, 2021):

Thanks @waydabber for letting people know about Lunar! Indeed, Lunar has Sync mode which takes advantage of Automatically adjust brightness by syncing the already adjusted brightness of the built-in display to the external monitors.

The problem with reading the sensor directly is that:

  1. It's not possible at all on Intel Macs (or at least I couldn't find a way to do it, the I/O Kit registry doesn't seem to expose any kind of lux or raw value)
  2. It's very hard to map the lux value to a brightness value when each single external monitor has its own lightness (nits) range
  3. You'll get more accurate results by reading the already adapted brightness of the builtin display because the system has an internal representation of the lightness curve of the display and can map it very well to the lux readings of the sensor.

If anyone is interested in reading the lux value on M1 Macs, because that is possible there, here is how to retrieve it from the command line:

ioreg -r -c AppleSPUCT720 | awk '/CurrentLux/{print $4}'

Doing that in Swift would require iterating the I/O Kit registry by matching the class AppleSPUCT720 and then extracting the CurrentLux property. Probably something like this:

#!/usr/bin/env swift

import IOKit
import Foundation

func getLux() -> Float? {
    let sensor: io_service_t
    if #available(macOS 12.0, *) {
        sensor = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("AppleSPUCT720"))
    } else {
        sensor = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleSPUCT720"))
    }

    guard sensor != 0 else {
        return nil
    }

    guard let luxProp = IORegistryEntryCreateCFProperty(sensor, "CurrentLux" as CFString, kCFAllocatorDefault, 0),
          let lux = luxProp.takeRetainedValue() as? Float
    else { return nil }

    return lux
}

print(getLux() ?? -1)
<!-- gh-comment-id:902970020 --> @alin23 commented on GitHub (Aug 20, 2021): Thanks @waydabber for letting people know about Lunar! Indeed, Lunar has Sync mode which takes advantage of **Automatically adjust brightness** by syncing the already adjusted brightness of the built-in display to the external monitors. The problem with reading the sensor directly is that: 1. It's not possible at all on Intel Macs (or at least I couldn't find a way to do it, the I/O Kit registry doesn't seem to expose any kind of lux or raw value) 2. It's very hard to map the lux value to a brightness value when each single external monitor has its own lightness (nits) range 3. You'll get more accurate results by reading the already adapted brightness of the builtin display because the system has an internal representation of the lightness curve of the display and can map it very well to the lux readings of the sensor. If anyone is interested in reading the lux value on M1 Macs, because that is possible there, here is how to retrieve it from the command line: ```sh ioreg -r -c AppleSPUCT720 | awk '/CurrentLux/{print $4}' ``` Doing that in Swift would require iterating the I/O Kit registry by matching the class `AppleSPUCT720` and then extracting the `CurrentLux` property. Probably something like this: ```swift #!/usr/bin/env swift import IOKit import Foundation func getLux() -> Float? { let sensor: io_service_t if #available(macOS 12.0, *) { sensor = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("AppleSPUCT720")) } else { sensor = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleSPUCT720")) } guard sensor != 0 else { return nil } guard let luxProp = IORegistryEntryCreateCFProperty(sensor, "CurrentLux" as CFString, kCFAllocatorDefault, 0), let lux = luxProp.takeRetainedValue() as? Float else { return nil } return lux } print(getLux() ?? -1) ```
Author
Owner

@waydabber commented on GitHub (Aug 20, 2021):

Wow @alin23 thanks for the detailed info! I wanted to go on the route of reading the internal display brightness (as that will also help on an other request, namely the use of the MBP touch bar slider for brightness change - I think we have a similar situation there that we can only infer the selected brightness only from the display's brightness itself, but I am not entirely sure, since I don't have an MBP myself and hate the idea of the touchbar. :))

But there is a rather long list of other accumulated issues to be dealt with so I am afraid this one does not have the highest prioirty at the moment.

<!-- gh-comment-id:902987396 --> @waydabber commented on GitHub (Aug 20, 2021): Wow @alin23 thanks for the detailed info! I wanted to go on the route of reading the internal display brightness (as that will also help on an other request, namely the use of the MBP touch bar slider for brightness change - I think we have a similar situation there that we can only infer the selected brightness only from the display's brightness itself, but I am not entirely sure, since I don't have an MBP myself and hate the idea of the touchbar. :)) _But there is a rather long list of other accumulated issues to be dealt with so I am afraid this one does not have the highest prioirty at the moment._
Author
Owner

@waydabber commented on GitHub (Aug 26, 2021):

Here is what we can do regarding the ambient light sensor, the touch bar slider and the Control Center brightness slider:

  • we cannot directly access the ambient light sensor on Intel macs (there is a way for M1 macs).
  • we cannot directly access the Touch Bar and Control Center brightness sliders.
  • we cannot receive a notification if the internal display (or external Apple display) brightness is changed.
  • we can poll the current brightness level of the internal display (or external Apple displays with built in ambient light sensor).

Based on this, we can do brightness change replication from the internal display to the external displays. The issues are still numerous:

  • How frequently should we poll? We might continuously poll the brightness level every 1 second and then if we detect change, increase the polling level. This will still not result in an immediate replication if the sliders are used but better then nothing. Increasing polling frequency taxes the system.
  • Currently MonitorControl changes the brightness of the screen that has the mouse cursor. Should the synchronization affect all screens or only the screen with the pointer? The eariler is logical if the goal is to have a general ambient light sensor synchronization thing, the latter is if we want the macbook slider to change the brightness of the current screen in focus (+ the built in screen since we can't do anything stopping that).
  • If we want synchronization to affect all screens, then we also need a mechanism to "calibrate" relative brightness levels of the external displays (or mandate software dimming since with that we can replicate better the full range of internal screen's brightness range which typically a magnitude better than what most displays have). Or we might want to do an offset based synchronization and allow for quick calibration whenever the user wants his/her external display to be brighter or dimmer than what the app is setting, independently from the internal display.

This issue is related if we want all out synchronization: https://github.com/MonitorControl/MonitorControl/issues/418

I am not yet sure where to go with this and how well would the end result work. :)

<!-- gh-comment-id:906661021 --> @waydabber commented on GitHub (Aug 26, 2021): Here is what we can do regarding the ambient light sensor, the touch bar slider and the Control Center brightness slider: - we cannot directly access the ambient light sensor on Intel macs (there is a way for M1 macs). - we cannot directly access the Touch Bar and Control Center brightness sliders. - we cannot receive a notification if the internal display (or external Apple display) brightness is changed. - we can poll the current brightness level of the internal display (or external Apple displays with built in ambient light sensor). Based on this, we can do brightness change replication from the internal display to the external displays. The issues are still numerous: - How frequently should we poll? We might continuously poll the brightness level every 1 second and then if we detect change, increase the polling level. This will still not result in an immediate replication if the sliders are used but better then nothing. Increasing polling frequency taxes the system. - Currently MonitorControl changes the brightness of the screen that has the mouse cursor. Should the synchronization affect all screens or only the screen with the pointer? The eariler is logical if the goal is to have a general ambient light sensor synchronization thing, the latter is if we want the macbook slider to change the brightness of the current screen in focus (+ the built in screen since we can't do anything stopping that). - If we want synchronization to affect all screens, then we also need a mechanism to "calibrate" relative brightness levels of the external displays (or mandate software dimming since with that we can replicate better the full range of internal screen's brightness range which typically a magnitude better than what most displays have). Or we might want to do an offset based synchronization and allow for quick calibration whenever the user wants his/her external display to be brighter or dimmer than what the app is setting, independently from the internal display. This issue is related if we want all out synchronization: https://github.com/MonitorControl/MonitorControl/issues/418 I am not yet sure where to go with this and how well would the end result work. :)
Author
Owner

@waydabber commented on GitHub (Sep 11, 2021):

Just some info about the progress regarding this issue:

  • There is now polling for the internal screen + sliders are updating based on change which was implemented when solving https://github.com/MonitorControl/MonitorControl/issues/198. This works nicely whenever the ambient light sensor kicks in or the touchbar slider is used. This is a foundation to have the brightness replicated among other displays.
  • Some other things are needed until proper synchronization can be done. These are #310, #418 and #570. These are interlocked issues and I am in progress of making it work.
  • Once the above are done, this and #334 will logically follow.
<!-- gh-comment-id:917403805 --> @waydabber commented on GitHub (Sep 11, 2021): Just some info about the progress regarding this issue: - [x] There is now polling for the internal screen + sliders are updating based on change which was implemented when solving https://github.com/MonitorControl/MonitorControl/issues/198. This works nicely whenever the ambient light sensor kicks in or the touchbar slider is used. This is a foundation to have the brightness replicated among other displays. - [x] Some other things are needed until proper synchronization can be done. These are #310, #418 and #570. These are interlocked issues and I am in progress of making it work. - [ ] Once the above are done, this and #334 will logically follow.
Author
Owner

@waydabber commented on GitHub (Sep 19, 2021):

Brightness change synchronization from Built-In and Apple displays to other displays is now added. This makes Touch Bar, Ambient light sensor, Control Center and System Preferences induced changes affect all displays. Synchronization is not direct, but only changes are replicated - the user can intervene and adjust at any time.

https://github.com/MonitorControl/MonitorControl/discussions/596

<!-- gh-comment-id:922435185 --> @waydabber commented on GitHub (Sep 19, 2021): Brightness change synchronization from Built-In and Apple displays to other displays is now added. This makes Touch Bar, Ambient light sensor, Control Center and System Preferences induced changes affect all displays. Synchronization is not direct, but only changes are replicated - the user can intervene and adjust at any time. https://github.com/MonitorControl/MonitorControl/discussions/596
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/MonitorControl#27
No description provided.