Ubuntu – How to use xbacklight with brightness keys in a VAIO

12.04backlightbrightnesssonyvaio

I have a Sony VAIO VPCCW15FL, with Ubuntu 12.04 installed.

Sadly, the brightness keys do not work out of the box, although the brightness meter reacts to the brightness up/down keypresses.

Yesterday, I installed xbacklight and tried it from the terminal. As a normal user (without sudo), I can run xbacklight -40, for example, and the backlight dims. It works great.

I then opened the Keyboard settings, and tried to set up two custom shortcuts for controlling the backlight brightness. I named one as "Brightness up", with xbacklight +10 as its command. Then I clicked to set the key, and "Monitor brightness up" showed up (as the key), so it was detected. However, even after rebooting, it didn't work. I tried changing the command to /usr/bin/xbacklight +10 but it didn't work either.

What's wrong with this? Also, I would like to know if I can make the brightness meter use the xbacklight command instead of its default. Is there any file I can change to do this? I think that would be even better than defining the shortcuts since it would integrate with the brightness bar. Thanks 🙂

Best Answer

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