Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Also an easy Q: How do I set screen brightness?

Also an easy Q: How do I set screen brightness?
Thread Tools
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jun 17, 2002, 05:53 PM
 
I'd like to make a very simple command-line tool that can:
1. Set/read the monitor brightness (the actual lamp, not a ColorSync thing)
2. Set/read the system volume -- Nevermind, found this one

Any guidance on what system calls to use, or sample code?

Since everyone was so wonderfully helpful with my last question, I thought I'd push my luck and try a couple more. I've nosed around Developer Connection, googled, and grepped in /usr/include and /System/Library/Frameworks/ without success on these seemingly straightforward topics. Perhaps what I really need is advice on better ways to figure this stuff out!

(again, for the curious, this too is part of my remote control system. The reasons to want to set system volume should be obvious. I want to change monitor brightness so that you can blacken the screen while you're remote-controlling your Mac. That way you can do stuff at your Mac without everyone walking by able to see what you're up to...)

TIA - Mithras

[EDIT: Found the system volume controls ]

<small>[ 06-18-2002, 07:41 AM: Message edited by: Mithras ]</small>
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jun 18, 2002, 12:40 PM
 
See either CoreGraphics.framework or IOKit.framework, methinks.
     
Mithras  (op)
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jun 19, 2002, 11:27 PM
 
Sorry, other than a cryptically named constant, all my best grepping and handreading through those frameworks and others hasn't turned up an obvious API for monitor brightness.

Anyone know of how to read or set brightness, or have further ideas on how to find one?
     
Junior Member
Join Date: Jul 2001
Location: Mos Eisley Cantina
Status: Offline
Reply With Quote
Jun 20, 2002, 01:55 AM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">
Sorry, other than a cryptically named constant, all my best grepping and handreading through those frameworks and others hasn't turned up an obvious API for monitor brightness.

Anyone know of how to read or set brightness, or have further ideas on how to find one?
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">It's most likely done using IOKit.

One way you may try and figure it out is if you have a PowerBook; when you press the brightness keys, loginwindow changes the LCD's backlight intensity for you. Unfortunately, you can't run Sampler on loginwindow, so you have to use gdb instead.

You can set breakpoints on likely IOKit functions and see what parameters are used (I don't know much about IOKit, so I don't know how feasible this is).

Or you can see what happens when loginwindow receives the keyboard event for the brightness key being hit.
     
Grizzled Veteran
Join Date: Dec 2000
Location: Málaga, Spain, Europe, Earth, Solar System
Status: Offline
Reply With Quote
Mar 25, 2003, 04:04 AM
 
Originally posted by PipelineStall:
One way you may try and figure it out is if you have a PowerBook; when you press the brightness keys, loginwindow changes the LCD's backlight intensity for you. Unfortunately, you can't run Sampler on loginwindow, so you have to use gdb instead.
Well, you can also change brightness from withint the System Preferences application, in the Display panel. It is posible to track down that using Sampler?

I tried, but I am no expert in using Sampler... anyone?

Thanks.
     
Mithras  (op)
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Mar 25, 2003, 12:11 PM
 
Woah, blast from the past.

Incidentally, I ended up just setting the monitor gamma to zero, which turns the screen black, without actually changing the monitor brightness.

This turned out to be better for my purposes: I was patching OSXvnc-server to turn the screen black when a user connects, so you could use VNC remotely and keep people nearby from seeing what you're doing on the screen.

VNC can't read the screenbuffer if the brightness is turned all the way down, so using the Gamma worked better.

If anyone cares, these were the simple functions I wrote:
Code:
CGGammaValue redMin; CGGammaValue redMax; CGGammaValue redGamma; CGGammaValue greenMin; CGGammaValue greenMax; CGGammaValue greenGamma; CGGammaValue blueMin; CGGammaValue blueMax; CGGammaValue blueGamma; CGDisplayErr dimSaveGamma() { return CGGetDisplayTransferByFormula( kCGDirectMainDisplay, &redMin, &redMax, &redGamma, &greenMin, &greenMax, &greenGamma, &blueMin, &blueMax, &blueGamma); } CGDisplayErr dimDimGamma() { return CGSetDisplayTransferByFormula( kCGDirectMainDisplay, redMin, 0.0, redGamma, greenMin, 0.0, greenGamma, blueMin, 0.0, blueGamma); } CGDisplayErr dimRestoreGamma() { return CGSetDisplayTransferByFormula( kCGDirectMainDisplay, redMin, redMax, redGamma, greenMin, greenMax, greenGamma, blueMin, blueMax, blueGamma); }
     
Grizzled Veteran
Join Date: Dec 2000
Location: Málaga, Spain, Europe, Earth, Solar System
Status: Offline
Reply With Quote
Mar 25, 2003, 02:26 PM
 
Well I really want to adjust brightness using software, as I try to write an application that sets the brightness when the battery status change.

Yes it is a recovered topic, I did a search over the forums instead of starting a new thread, I found this one that suits perfectly my questions
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:25 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2