Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Adjust brightness from Terminal UNIX
I've searched for a way to control the display brightness from the command line. I found several AppleScripts that open the System Preferences panel and set the slider, but I wanted a pure command line tool. Maybe someone else is looking for the same solution, so here is what I found:

This blog post discusses has a small commandline tool (written by Nicholas Riley) to set the brightness from Terminal. Just download the binary [4KB] and install it. You can then set the brightness by typing brightness 0 (to set it to minimum, use 1 for maximum, or any value between).

Note: The binary is Intel-Only (32-Bit), but the source code is available on the above linked page too, so you could easily compile a PowerPC or 64Bit Intel Binary on your own. I've tested it only with Snow Leopard and a self-compiled 64Bit binary, and it works fine
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[3,126 views]  

Adjust brightness from Terminal | 9 comments | Create New Account
Click here to return to the 'Adjust brightness from Terminal' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Adjust brightness from Terminal
Authored by: billearl on Mon, Sep 14 2009 at 12:21PM PDT
For the uninitiated such as myself, PowerPC and 64Bit binaries, along with their installation location, would be useful. Thanks.

[ Reply to This | # ]
Adjust brightness from Terminal
Authored by: sabi on Mon, Sep 14 2009 at 1:07PM PDT
I'm the original author of the code listed in this hint. I originally wrote it for two reasons: first, to adjust brightness automatically by location on my iBook G4, which had no ambient light sensor, and second, so I could have my laptop turn on the backlight when a long operation finished, providing a quiet form of notification I could use while at a seminar.

http://sabi.net/nriley/software/brightness.zip is 4-way universal, 10.5+. I compiled it under 10.6 with:


gcc-4.0 -arch i386 -arch x86_64 -arch ppc -arch ppc64 -isysroot /Developer/SDKs/MacOSX10.5.sdk \
-mmacosx-version-min=10.5 -std=c99 -o brightness \
-framework Cocoa -framework DisplayServices \
-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/PrivateFrameworks brightness.m
(note that if you compile it with the 10.6 SDK you'll get a deprecation warning; it's harmless for now.)

[ Reply to This | # ]
Adjust brightness from Terminal
Authored by: billearl on Tue, Sep 15 2009 at 8:01PM PDT
Thanks for this!

Just copied it to /usr/local/bin on my iBook G4 and it works great.

[ Reply to This | # ]
64-bit
Authored by: bankshot on Wed, Sep 16 2009 at 9:10AM PDT

I guarantee that 64-bit won't gain you anything at all in this case over 32-bit running on Intel. This is such a small and simple application that there's no benefit whatsoever to going beyond 32-bit, even on a system running all 64-bit stuff otherwise. Well, maybe a tiny psychological advantage for those who absolutely can't stand to have their system "polluted" by 32-bit stuff, but certainly no real-world advantage. ;)

That said, many thanks to the original author and to the hint submitter for calling attention to it! This program gives me a great idea to simulate an intermittent screen problem in my custom anti-theft script for my MacBook. Can't wait to try it out.



[ Reply to This | # ]
Adjust brightness from Terminal
Authored by: corienti on Mon, Sep 14 2009 at 2:32PM PDT
Absolutely brilliant! Thankyou!

[ Reply to This | # ]
Adjust brightness from Terminal
Authored by: luomat on Mon, Sep 14 2009 at 3:35PM PDT
There are instructions to compile this on the linked page.

The only problem I found is that it only dims the screen of the main display, not a second display hooked to a laptop.



[ Reply to This | # ]
Adjust brightness from Terminal
Authored by: BobHarris on Mon, Sep 14 2009 at 8:20PM PDT
The original brightness.c had a -d (display) option. I've been using this program for about 1/2 a year now and it works very nicely. The usage is something like:
usage: brightness [-m|-d display] [-v] 
   or: brightness -l [-v]

       -l   - Display current setting
       -d n - Use Display n (0, 1, 2, ...)
       -m   - Use the Main Display
       -v   - verbose

       0.0 to 1.0 - set the brightness from off to max
       brightness 1    # Full brightness
       brightness 0.5  # Half brightness
       brightness 0    # Display off


[ Reply to This | # ]
Adjust brightness from Terminal
Authored by: mario_grgic on Tue, Sep 15 2009 at 3:16PM PDT
This only works on my aluminum macbook, and iMac, it does not work on my mac pro with 30'' ACD.

[ Reply to This | # ]
Adjust brightness from Terminal
Authored by: sabi on Tue, Sep 15 2009 at 7:32PM PDT
Yeah, unfortunately Apple doesn't have a documented way of controlling brightness over USB. The documented method only works with built-in and ADC displays.

Use the version I linked above (http://sabi.net/nriley/software/brightness.zip) instead; it uses the same method as the Displays preference pane does.

[ Reply to This | # ]