Contribute
Register

Work around for 4x30s screen brightness...

Status
Not open for further replies.

RehabMan

Moderator
Joined
May 2, 2012
Messages
181,058
Motherboard
Intel DH67BL
CPU
i7-2600K
Graphics
HD 3000
Mac
  1. MacBook Air
Mobile Phone
  1. iOS
I've been using this for a bit here and it seems to work pretty well... I wouldn't call it a fix, but rather a work around.

As you know, the 4x30s series brightness does not work correctly except after a 'display sleep'. What I describe here will allow a display sleep/wake to happen just after logging in. It is based on code originally posted by rybarkam here: http://www.tonymacx86.com/hp-probook/77058-faq-mountain-lion-hp-probook-2.html#post536702

The problem with rybarkam's solution is that it was buried in an app bundle instead of just a command line app, and it didn't work reliably. Probably because there was no control over the timing. So... I did a little tweaking. It involves several files/components:

1. blinkscreen binary, installed to /usr/bin

It is this code (blinkscreen.c):
Code:
/** GPL **/
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <unistd.h>
int main() {
    io_registry_entry_t entry = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
    if (entry) {
        IORegistryEntrySetCFProperty(entry, CFSTR("IORequestIdle"), kCFBooleanTrue);
        usleep(100*1000); // sleep 100 ms
        IORegistryEntrySetCFProperty(entry, CFSTR("IORequestIdle"), kCFBooleanFalse);
        IOObjectRelease(entry);
    }
    return 0;
}

Compiled with: gcc -Wall -mmacosx-version-min=10.6 -o blinkscreen blinkscreen.c -framework IOKit -framework Foundation

2. Plist to register a LaunchAgent, installed to /Library/LaunchAgents

org.rehabman.autoexec.plist:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>org.rehabman.autoexec</string>
	<key>RunAtLoad</key>
	<true/>
	<key>KeepAlive</key>
	<false/>
	<key>Program</key>
	<string>/usr/bin/autoexec.sh</string>
</dict>
</plist>

3. autoexec.sh script that runs per-user script in ~/autoexec.sh, installed to /usr/bin/autoexec.sh

/usr/bin/autoexec.sh
Code:
#!/bin/sh
# install to /usr/bin/autoexec.sh

# run ~/autoexec.sh if it exists
if [ -e ~/autoexec.sh ]; then
	~/autoexec.sh
fi

Make it executable with:
Code:
chmod +x /usr/bin/autoexec.sh

4. autoexec.sh script that does the actual work, installed to ~/autoexec.sh

Note: this is a generic mechanism... You can put anything you want in here. I also establish connections to my SMB shares on my WHS 2011 server, for example...

Note: If you wanted the blinkscreen to be run for all users, you could also enter this code into the /usr/bin/autoexec.sh. This might, in fact, be the best option were this to be placed in the ProBook Installer.

~/autoexec.sh
Code:
#!/bin/sh
# install to ~/autoexec.sh

# might not be necessary to sleep for a second, you can experiment with/without it...
sleep 1
# blink the screen, fixing the brightness issue...
/usr/bin/blinkscreen

Make it executable with:
Code:
chmod +x ~/autoexec.sh

This is a 'translation' of the code I'm using on my own machine, so hopefully I didn't create any errors with it here...

Maybe a possible option in the ProBook Installer v6.1??

Note: This solution is now available from the ProBook Installer v6.1b8 (and later). Easy checkbox to install!

Edit 2013-04-26: Updated binary below. Built with tools on Snow Leopard. Should be compatible now with all three SL, Lion, and ML.

blinkscreen binary is attached below:
 

Attachments

  • blinkscreen.zip
    1.6 KB · Views: 355
Note: To make two sh files runnable, cd to its direction than run the command:
Code:
chmod +x autoexec.sh

It works for me, but typing login password twice is weird somehow:problem::problem:

EDIT: You can get past the login screen by go to System Preferences > Security & Privacy > General > set Require password .... after sleep to 1 Minute, then you don't have to type password if sleep time is less than 1 minute.
 
Note: To make two sh files runnable, cd to its direction than run the command:
Code:
chmod +x autoexec.sh

Yes! ProBook Installer can take care of these details for us eventually... Note: Some text editors automatically make it the file executable if it starts with '#!/bin/sh'

It works for me, but typing login password twice is weird somehow:problem::problem:

EDIT: You can get past the login screen by go to System Preferences > Security & Privacy > General > set Require password .... after sleep to 1 Minute, then you don't have to type password if sleep time is less than 1 minute.

Yes, I probably should have mentioned the password timeout...
I wonder if there is a way to change that option from shell script?
 
Thanks RehabMan!
Do you use your display at full brightness after the blinking or do you set a custom brightness value with Philip Petev's script?:

for example:
Code:
<string>/usr/sbin/setbrightness</string>
<string>0.92</string>
 
Thanks RehabMan!
Do you use your display at full brightness after the blinking or do you set a custom brightness value with Philip Petev's script?:

for example:
Code:
<string>/usr/sbin/setbrightness</string>
<string>0.92</string>

I don't use the setbrightness at all. I find with the blinkscreen, brightness is restored to where it last was...
 
My ProBook doesn't seem to remember the brightness value. I set brightness to 90% then I restart the computer.
OS X is starting, the screen blinking happens but sets the brightness value back to 100%.
 

Attachments

  • brightness.jpg
    brightness.jpg
    204.5 KB · Views: 364
My ProBook doesn't seem to remember the brightness value. I set the the brightness to 90% then I restart the computer.
OS X is starting, the screen blinking happens but sets the brightness value back to 100%.

What boot loader?
 
Chimera 2.0.1

I don't think it makes a difference but I'm using Chameleon svn-r2187. Could be difference in 4x30s vs. 4x40s. BTW, I thought BigDonkey had reported that the brightness issue was not present on 4x40s?

Make sure you don't have setbrightness interfering...

And I verified again. I did the following:
- set the brightness 4 levels from brightest (4 dark squares on right)
- restarted
- logged in, waited for blinkscreen to kick in
- checked brightness with F2
- result: brightness was then set to five from brightest (5 dark squares on right)
- set brightness to 4 levels from lowest (4 bright squares on left)
- restarted
- logged in, waited for blinkscreen to kick in
- checked brightness with F2
- result: brightness was then set to three from brightest (3 bright squares on left)

In other words, other than the blinking display and having to login first, it works like it should.

Side note: I tried running the blinkscreen before login, but the OS calls it is making doesn't work at the login screen -- login screen seems 'special'...
 
I don't think it makes a difference but I'm using Chameleon svn-r2187. Could be difference in 4x30s vs. 4x40s. BTW, I thought BigDonkey had reported that the brightness issue was not present on 4x40s?

Yes, but he has Intel HD4000. I have HD 3000.
 
Status
Not open for further replies.
Back
Top