4

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.

4
  • Doesn't anyone has any idea? Sep 5, 2012 at 4:44
  • Is not there anyway to do this? Sep 7, 2012 at 11:34
  • I'm working on this and I'll post the solution in a few hours.
    – green
    Sep 7, 2012 at 14:28
  • posted the answer
    – green
    Sep 7, 2012 at 16:51

1 Answer 1

5

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
8
  • How can i change this script so that decrease brightness when my laptop is on battery too? Sep 7, 2012 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, 2012 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. Sep 7, 2012 at 17:02
  • I'll modify it. Wait a minute.
    – green
    Sep 7, 2012 at 17:04
  • added the changes.
    – green
    Sep 7, 2012 at 17:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .