Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

thanks.

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. –  green7 Sep 7 '12 at 14:28
    
@green7 Thank you i am waiting. –  Saeed Zarinfam Sep 7 '12 at 14:36
    
posted the answer –  green7 Sep 7 '12 at 16:51
add comment

1 Answer 1

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
do
    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" ] 
    then
        if ((batteryPercentage > 30))
        then
            xbacklight -set $batteryPercentage
        else
            xbacklight -set 0
        fi
    fi

    sleep 60
done
  • Copy this text to some file, say batteryBrightness.sh

  • 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.

Note:

  • 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. –  green7 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. –  green7 Sep 7 '12 at 17:04
1  
Accept the answer if you find it correct. –  green7 Sep 7 '12 at 17:13
show 5 more comments

Your Answer

 
discard

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.