10

I'm using the ioreg command line tool to try and read sensor information available on my computer (iMac). Particularly, I'd like to read the current value of the ambient light sensor. So far, I have been able to retrieve some general information regarding the sensor via ioreg -f -b -r -c 'AppleLMUController'. But the value is not there:

+-o AppleLMUController  <class AppleLMUController, id 0x1000002d8, registered, matched, active, busy 0 (0 ms), retain 7>
{
  "IOProbeScore" = 0
  "CFBundleIdentifier" = "com.apple.driver.AppleSMCLMU"
  "IOProviderClass" = "IOService"
  "IOClass" = "AppleLMUController"
  "IOMatchCategory" = "IODefaultMatchCategory"
  "IOCFPlugInTypes" = {"0516B563-B15B-11DA-96EB-0014519758EF"="AppleSMCLMU.kext/Contents/PlugIns/AmbientLightSensorHID.plugin"}
  "IOGeneralInterest" = "IOCommand is not serializable"
  "IONameMatch" = "ACPI0008"
  "IOPowerManagement" = {"MaxPowerState"=1,"CurrentPowerState"=1}
  "HIDServiceSupport" = Yes
  "IONameMatched" = "ACPI0008"
}

I know that there are tools that can use IOKit to access this value using C, ObjC, etc - but I explicitly would like to use a bash one-liner to try and grab the value.

Has anyone been able to successfully do this via the command line and if so, how?

3 Answers 3

1

You can't get the value of ambient light sensor from ioreg. For that, first you should install the system management controller smc .exec then run it using terminal. After that run this command:

./smc -l 

It shows the list of all sensors which exist on your Mac. After that try to find the key which is ALSL - this key has the actual value of light ambient sensor of every mac.

3
  • 1
    Where do you get smc from?
    – mmmmmm
    Jul 27, 2021 at 19:02
  • github.com/hholtmann/smcFanControl here is the link install it and then go to app content and find smc.exec there
    – Malik Ejay
    Jul 28, 2021 at 20:07
  • Please improve your answer by editing that information into your answer
    – mmmmmm
    Jul 28, 2021 at 20:28
1

I can propose you two commands that can give you the ambient light sensor value (in lux). Both commands achieve the same result, but the difference lies in the registry keys they search for and the methods they use to retrieve the value.


The following command will output the ambient light sensor value in lux (metric unit for luminosity):

ioreg -w0 -r -c AppleLMUControllerUserClient | grep -i "light sensor"

This command basically searches for the "light sensor" string in the ioreg registry for the AppleLMUControllerUserClient class, which is responsible for managing the Light Management Unit (LMU) controller on the Mac's logic board, which includes the ambient light sensor.

You should something like that:

| |   "Light Sensor" = 2.993712

Another method would be to specifically target the backlight display node, search for the "AmbienLight" key in the ioreg registry and retrieve it:

ioreg -l -n "AppleBacklightDisplay" | grep "AmbientLight"

For this command the output should look like this:

| |   |   |   |   |   "DisplayBrightness" = 15159
| |   |   |   |   |   "AmbientLight" = 13

The number after AmbientLight is the current ambient light reading in lux, and the number after DisplayBrightness is the current screen brightness value, just look at the AmbientLight value.


Note: Some Mac models do not have an ambient light sensor, so these methods may not work on those devices. Also, some newer Mac models may use a different sensor technology that is not compatible with this method.

0

Read the current setting

defaults read com.apple.BezelServices dAuto

Write

defaults write com.apple.BezelServices dAuto -boolean true/false

2
  • 2
    Doesn't work for me: The domain/default pair of (.../com.apple.BezelServices, dAuto) does not exist
    – mbeasley
    Sep 10, 2014 at 12:46
  • 1
    com.apple.BezelServices exists but dAuto does not. dAuto being boolean suggests that this setting is to turn automatic light sensing off or on rather than to read the value of the sensor.
    – Freiheit
    Jul 27, 2016 at 13:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .