2

The idea being that, once the brightness passes a certain level, one could switch to a different visual scheme to give greater visibility. Also, if it could be some sort of listener type thing, that would be even better, but I'll take what I can get.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146

3 Answers3

3

I believe one could look it up with IOKit. Running the ioreg command in the terminal as below gives two lines where a brightness value is visible.

% ioreg -c AppleGraphicsControlBacklight | grep brightness

| | |     "IODisplayParameters" = {"brightness"={"min"=0,"value"=408,"max"=1024},"commit"={"reg"=0}}
| |   |     "IODisplayParameters" = {"brightness"={"min"=0,"value"=408,"max"=1024},"commit"={"reg"=0}}

Maybe someone with enough IOKit knowledge could put together a sample...

epatel
  • 45,805
  • 17
  • 110
  • 144
  • 1
    ioreg -c AppleGraphicsControlBacklight | grep brightness returns nothing. I have MAC Mojave 10.14.6 – barath Oct 07 '20 at 17:15
3

epatel was pretty close, I just had to change the AppleGraphicsControlBacklight keyword to something else to get it to work on my macbook, so I'd guess that this is something that might change between OSX versions and/or macbook versions.

I threw together a short ruby script to print out a little visual indicator on the command line.

# grab the string containing the values
brite_string = `ioreg -c AppleBacklightDisplay | grep brightness`

# build a regex to match those vals
brite_regex  = /"brightness"=\{"min"=([0-9]{1,3}),"value"=([0-9]{1,3}),"max"=([0-9]{1,3})/

# match them
match_data = brite_regex.match(brite_string)

# extract the values from the match
min = match_data[1].to_i
val = match_data[2].to_i
max = match_data[3].to_i

# print them out nice
puts "Current Brightness"
print "["

max.times do  |i|
  print i > val ? " " : "*"
end

puts "]"
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
  • Great scripting...I thought a more C/C++/ObjC solution was actually wanted. It should be possible accessing it through IOKit then... – epatel Feb 15 '09 at 09:52
  • Eventually, yeah, I might want something a little more connected to IOKit. This is basically just a proof of concept. – Paul Wicks Feb 16 '09 at 04:46
-3

I am not a mac guy, but does /proc exist in the filesystem? You might want to look in that virtual file directory if it exists.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • /proc doesn't exist on Max OS X. I don't know if some other directory plays the same role. – mouviciel Feb 13 '09 at 21:23
  • hm.. yea just taking a guess since linux and OS X are more or less cousins. –  Feb 13 '09 at 21:50
  • /proc does exist, but isn't mounted on the filesystem. You can still access it programatically. [citation-needed] – strager Feb 13 '09 at 22:38