macoslcdscreen-brightness

Is there a way to query the current brightness level of a the MacBook LCD?


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.


Solution

  • 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 "]"