Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When i work in Kubuntu, KDE power management has a section that lets you automatically adjust display brightness according to battery percentage.

I want to know if there is a tool like that in Ubuntu 12.04?


share|improve this question
Doesn't anyone has any idea? – Saeed Zarinfam Sep 5 '12 at 4:44
Is not there anyway to do this? – Saeed Zarinfam Sep 7 '12 at 11:34
I'm working on this and I'll post the solution in a few hours. – green Sep 7 '12 at 14:28
@green7 Thank you i am waiting. – Saeed Zarinfam Sep 7 '12 at 14:36
posted the answer – green Sep 7 '12 at 16:51
up vote 5 down vote accepted

Here is a script that checks the remaining battery every minute and adjusts the brightness accordingly. However, once the battery is below 30%, it sets the brightness to 0.

#! /bin/bash

while true
    chargingState=$(grep "charging state:" /proc/acpi/battery/BAT0/state | awk '{print $3}')
    batteryFull=$(grep "design capacity:" /proc/acpi/battery/BAT0/info | awk '{print $3}')
    batteryRemaining=$(grep "remaining capacity:" /proc/acpi/battery/BAT0/state | awk '{print $3}')

    batteryPercentage=$((batteryRemaining * 100/batteryFull))

    if [ $chargingState == "discharging" ] 
        if ((batteryPercentage > 30))
            xbacklight -set $batteryPercentage
            xbacklight -set 0

    sleep 60
  • Copy this text to some file, say

  • Make your script executable.

chmod +x /path/to/script
  • Open Startup Applications, from the cog menu present at the upper right corner.

Cog menu

  • Click on Add.

Startup Applications Dialog

  • Fill in all the details and click Add.

Add Startup Application Preferences

  • Logout and login back to check.


  • Change the name of the script to whatever you have named it, wherever required.
  • You'd need the xbacklight package installed, if you don't have it installed, install it by running the following command:
    sudo apt-get install xbacklight
share|improve this answer
How can i change this script so that decrease brightness when my laptop is on battery too? – Saeed Zarinfam Sep 7 '12 at 16:55
It changes according to the remaining battery percentage. It doesn't matter whether you're battery is charging or discharging. – green Sep 7 '12 at 16:57
It is important to me because i do not want i change brightness when i am on AC power, battery percentage is not important for me. – Saeed Zarinfam Sep 7 '12 at 17:02
I'll modify it. Wait a minute. – green Sep 7 '12 at 17:04
Accept the answer if you find it correct. – green Sep 7 '12 at 17:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.