Skip to content

Instantly share code, notes, and snippets.

@edwardean
Created August 29, 2016 08:54
Show Gist options
  • Select an option

  • Save edwardean/d5fe31c5fedea5ecb7a43f3b3cdf905e to your computer and use it in GitHub Desktop.

Select an option

Save edwardean/d5fe31c5fedea5ecb7a43f3b3cdf905e to your computer and use it in GitHub Desktop.
//CGDisplayIOServicePort is depreciated in OS 10.9 – so you have to use IOServiceGetMatchingServices to get the service parameter for IODisplaySetFloatParameter.
- (void) setBrightnessTo: (float) level
{
io_iterator_t iterator;
kern_return_t result = IOServiceGetMatchingServices(kIOMasterPortDefault,
IOServiceMatching("IODisplayConnect"),
&iterator);
// If we were successful
if (result == kIOReturnSuccess)
{
io_object_t service;
while ((service = IOIteratorNext(iterator))) {
IODisplaySetFloatParameter(service, kNilOptions, CFSTR(kIODisplayBrightnessKey), level);
// Let the object go
IOObjectRelease(service);
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment