Tuesday, 20 June 2006
Setting display brightness: updated tool
Here is my cleaned-up brightness tool, which now uses the IOKit APIs instead of the weird O3Engine SPIs that the old version did.
Quick example:
% ./brightness usage: ./brightness [-m|-d display] [-v] <brightness> or: ./brightness -l [-v] % ./brightness -l display 0: main display, ID 0x4270a80 display 0: brightness 0.734375 % ./brightness -v 0.3 display 0: brightness 0.296875
-m changes the brightness of the main display; -d changes brightness of whatever display number/ID you provide. -l -v dumps display attributes—sorry for the ugly XML output, but CoreFoundation claims to be unable to output an OpenStep-format property list even though Cocoa has no problem doing the same.
11:07 AM |
hi,
i had to move the “const CFString…” (line 9) to inside of the main function to get this to compile on os x 10.4.7, xcode 2.3 (using your 1st line comment in the terminal to compile).
thanks,
-matt
When you say “Cocoa has no problem”, are you referring to -description or NSPropertyListSerialization? AFAIK, the latter simply maps to the CF functions, and will fail in the same way.
I’m just referring to -description. I don’t care about serialization, just making something human-readable.
[…] http://njr.sabi.net/2006/06/20/setting-display-brightness-updated-tool/ […]
I run this code on an intel imac with external 23 inch display. It doesn’t work for the external display :
[Session started at 2007-01-05 11:26:18 +0100.]
display 0: main display, ID 0×424a6d5
/Users/schelfd/dev/testB/bright/build/Debug/bright: failed to get brightness of display 0×424a6d5 (error -536870201)display 1: ID 0×4271600
display 1: brightness 0.000000
bright has exited with status 0.
I believe the error is : // device read locked
I tried running as root as well and changing the main display
I run 40.4.8
Yeah, I’ve had this report from someone else too. I don’t have a dual-display machine to test with unfortunately - when I first wrote it, I had access to a Power Mac G5 with two displays and it did work fine on both.
You are using an external Apple Cinema display (aluminum bezel, DVI)?
Confirmed that the IOKit-based methods do not work with Intel-based desktop systems with externally-attached Apple Cinema displays.
In my specific case, IODisplayGetFloatParameter(…, CFSTR(kIODisplayBrightnessKey), …) returns ‘kIOReturnUnsupported’ on a Mac Pro with twin 20″ Apple Cinema displays whereas it works just fine on my MacBook Pro C2D.