nriley/brightness

System brightness setting is not updated (macOS 10.13.1)

mafredri opened this issue · 18 comments

It seems brightness does not update the brightness setting in the system. This can be observed from the display settings (System Preferences > Displays), the slider does not change even after quitting / reopening preferences.

This can also be observed on a Touch Bar, the position of the brightness slider does not update after running brightness.

Steps to reproduce:

  1. Set brightness to max (in System Preferences)
  2. Quit System Preferences
  3. Run brightness 0.5
  4. Check brightness in System Preferences, still at max

I think this is related to #20.

Looks like there is now a CoreBrightness.framework and CoreDisplay.framework and these override the IOKit method that brightness uses. Apple doesn't document this at all, so unless someone wants to reverse engineer it (and that someone is not me), brightness will stay broken. Sorry.

I'm experiencing either this one or #20 as well (or both) on macOS 10.13.6. The revert to the previous brightness setting seems to happen within a few seconds of switching windows after running e.g., brightness 0.5.

In case someone is stuck on this, I made a quick tool for managing the the brightness of the internal MacBook display macos-brightness (the internal display limitation is just because I didn't bother making it more flexible).

@nriley if you're interested in fixing this issue, there's essentially two private APIs, part of CoreBrightness that can be used:

double CoreDisplay_Display_GetUserBrightness(CGDirectDisplayID id);
void CoreDisplay_Display_SetUserBrightness(CGDirectDisplayID id, double b);

I've only tested this on Mojave, but I imagine it should work on High Sierra as well.

@mafredri I just tried your package on 10.13.6 and it's working for me just fine.

I did get some warnings on install.

$ go get -u github.com/mafredri/macos-brightness/cmd/brightness
# github.com/mafredri/macos-brightness/cmd/brightness
ld: warning: text-based stub file /System/Library/Frameworks//CoreDisplay.framework/CoreDisplay.tbd and library file /System/Library/Frameworks//CoreDisplay.framework/CoreDisplay are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//CoreGraphics.framework/CoreGraphics.tbd and library file /System/Library/Frameworks//CoreGraphics.framework/CoreGraphics are out of sync. Falling back to library file for linking.
# github.com/mafredri/macos-brightness/cmd/brightness
ld: warning: text-based stub file /System/Library/Frameworks//CoreDisplay.framework/CoreDisplay.tbd and library file /System/Library/Frameworks//CoreDisplay.framework/CoreDisplay are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//CoreGraphics.framework/CoreGraphics.tbd and library file /System/Library/Frameworks//CoreGraphics.framework/CoreGraphics are out of sync. Falling back to library file for linking.

In case someone is stuck on this, I made a quick tool for managing the the brightness of the internal MacBook display macos-brightness (the internal display limitation is just because I didn't bother making it more flexible).

@nriley if you're interested in fixing this issue, there's essentially two private APIs, part of CoreBrightness that can be used:

double CoreDisplay_Display_GetUserBrightness(CGDirectDisplayID id);
void CoreDisplay_Display_SetUserBrightness(CGDirectDisplayID id, double b);

I've only tested this on Mojave, but I imagine it should work on High Sierra as well.

Hi @mafredri, thanks! This seems like it'd be pretty easy to change (much nicer than the last SPI I reverse engineered years ago!) and may resolve some of the issues people have reported with brightness. I've got some upcoming deadlines but do plan on adopting this if it works as well as you say.

Hi @nriley,
Great Tool!
I still have these issues with a download I did today. Would be really awesome to get it working again. It's the best tool around for setting the brightness easily via terminal. Have you been able to test @mafredri 's proposal?
Unfortunately I have no clue of programming otherwise I could try myself..
All the best,
Jonas

Thanks @colneck for the reminder (and @mafredri for the original suggestion) — finally got around to this. I've only tested on 10.14.5 with my MacBook Pro’s built-in display but I suspect it’ll work much more widely. @colneck let me know if you can compile it yourself or you need me to post a binary.

Unlike the function keys it doesn't seem to update System Preferences if it's open; there's obviously some kind of notification mechanism that this doesn't trigger. (Update: I fixed this).

From what I can tell the CoreDisplay stuff goes back to at least 10.12.6 and I suspect 10.12.4 since that was where Night Shift was introduced. I haven't tested to see if it breaks pre-10.12 yet but will do so before announcing a new release. If it works, I plan on switching the minimum OS release to 10.8 since many years have passed.

Wow, that was pretty fast! Thank you so much!
I installed it using your instructions to compile from code. Works like a charm now! Great little helper! :)

This method seems a bit different compared to how system handles brightness setting. By system I mean from preferences or touch bar.

Brightness change from system changes the color contrast a bit as well so it looks a more natural increase in brightness whereas this just makes the screen whiter (like increasing brightness of picture).

Any one else experiencing this?

This method seems a bit different compared to how system handles brightness setting. By system I mean from preferences or touch bar.

Brightness change from system changes the color contrast a bit as well so it looks a more natural increase in brightness whereas this just makes the screen whiter (like increasing brightness of picture).

Any one else experiencing this?

What Mac/macOS/display are you using? Are you using the latest code with the changes discussed in this issue?

What Mac/macOS/display are you using? Are you using the latest code with the changes discussed in this issue?

I am using 10.14.6. I am not using your tool. I was trying the method described in this thread.

Would recommend you try the latest code before reporting issues then.

Would recommend you try the latest code before reporting issues then.

Seems your tool works fine. Will have a look at your code to see what I am doing wrong.
Thank you

Great tool. Thank-you.
Installing via Homebrew on macOS 10.14.6 (18G95) seems to not work:

$ brew install brightness
/usr/local/Homebrew/Library/Homebrew/global.rb:12:in require': cannot load such file -- active_support/core_ext/object/blank (LoadError) from /usr/local/Homebrew/Library/Homebrew/global.rb:12:in <top (required)>'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in require_relative' from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in

'

However installing from Source did just fine.

Great tool. Thank-you.
Installing via Homebrew on macOS 10.14.6 (18G95) seems to not work:

$ brew install brightness
/usr/local/Homebrew/Library/Homebrew/global.rb:12:in require': cannot load such file -- active_support/core_ext/object/blank (LoadError) from /usr/local/Homebrew/Library/Homebrew/global.rb:12:in <top (required)>'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in require_relative' from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in

'
However installing from Source did just fine.

Please report the Issue to Home-brew rather than this thread or repository.