iSight Ambient Sensor

cocoa, isight, macos, objective-c, xcode

Solution

You can access the light sensor with IOService, from the IOKit library. The name for the light sensor is "AppleLMUController". Here's a good example: light sensor. Simply put, get the service like this: `io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleLMUController"));` Then, connect to the service using:

io_connect_t port = 0;
IOServiceOpen(service, mach_task_self(), 0, &port);

Get the light levels using: `IOConnectMethodScalarIScalarO(port, 0, 0, 2, &left, &right);` Where `left` and `right` are integers that now hold the light levels of the sensors. Note that many IOService methods return a `kern_return_t` variable, which will hold `KERN_SUCCESS`, unless the method failed. Also be sure to release the service object using `IOObjectRelease(service);`

EDIT: On second thought, `IOConnectMethodScalarIScalarO()` appears to be deprecated. Instead, use:

uint32_t outputs = 2;
uint64_t values[outputs];

IOConnectCallMethod(port, 0, nil, 0, nil, 0, values , &outputs, nil, 0);

The left and right values will be stored in `values[0]` and `values[1]` respectively. Be aware that not all MacBooks work this way: on my mid 2010 15'' pro, both values are the same, as the light sensor is in the iSight camera.

Problem

I realize there is not any public documentation about the use of the isight light sensor, however programs such as ShadowBook (shown here) are able to access the the brightness data and I was simply wondering if anyone has been able to achieve a similar result and know how to access this sensor? Thanks!

Original source