How to use xbacklight with brightness keys in a VAIO

Solution 1:

Ok, I got to a different solution that should work for other laptops too, not only for VAIOs.

Make sure that xbacklight and inotify-tools are installed, I just ran sudo apt-get install xbacklight inotify-tools .

Configure the following script and save it as a bash script (for example, save it as backlight_control.sh), and give it executable permissions with chmod +x backlight_control.sh.

Then add it to your startup applications (can be done in 12.04 by clicking on the menu item on the top-right corner of the screen). The backlight level should be restored to its previous setting, and the controls should start working, after you log into your session. The brightness meter displays the correct value too.

I hope this helps in case someone else is having the same issue. Any comments on its performance or anything else are welcome.

#!/bin/bash

# Script for setting the correct brightness for the backlight.
# Depends on: xbacklight and inotify-tools,
# Which can be installed by running:
#       `sudo apt-get install xbacklight inotify-tools`
#
# Author: Esteban Serrano Roloff <e.serrano.r (at) me.com>
#
# Tested on a Sony VAIO VPCCW15FL
# running Ubuntu 12.04
# 2013-03-27 (YYYY-MM-DD)

# Setup the correct paths (look inside /sys/class/backlight/)
current_brightness_path="/sys/class/backlight/sony/brightness"
max_brightness_path="/sys/class/backlight/sony/max_brightness"
# To find the correct value for min_brightness, make the
# brightness meter go to its minimum (by repeatedly pressing
# the brightness down key), even if the actual brightness stays
# the same, and then run on a terminal:
#       `cat /sys/class/backlight/sony/brightness`
min_brightness=0


#### No editing needed beyond this line (I hope) ####
max_brightness=`cat $max_brightness_path`
range=${max_brightness-min_brightness}



# Set the correct brightness level on start up.
current_brightness=`cat $current_brightness_path`
let current_brightness_pctg=100*$current_brightness/$range
xbacklight =$current_brightness_pctg

# Listen for brightness changes, forever.
while inotifywait -e close_write $current_brightness_path; do

    current_brightness=`cat $current_brightness_path`
    let current_brightness_pctg=100*$current_brightness/$range
    xbacklight =$current_brightness_pctg

done