Ubuntu: power.d display brightness by AC/Battery mode

I believe someone unplugged my AC cord in the school's library and put hers in the same socket, despite 3 other available sockets next to it. I did not realize it until I finished my studies.

Hence, I was determined to have my Ubuntu alert me as Windows does, when the power adapter is unplugged, there should be an alert. In this case, the preferred reaction would be to dim the screen brightness. However, I have learned that it was very time consuming to find a solution.

First, there were no user-friendly configurations available. Then, after having pm-utils and writing scripts in /etc/pm/power.d/, I've encountered the xauth issue. Thereby preventing xbacklight from accessing the X server due to the lack of privilege from the power.d. I researched into this for too long to no avail.

Then I reverted back to the original solution I found but abandoned for some reason I don't remember.

Now it works with this script in power.d:

#!/bin/sh
case $1 in
    true) #laptop_mode_battery 
        expr `cat /sys/class/backlight/acpi_video0/max_brightness` / 3 > 
            /sys/class/backlight/acpi_video0/brightness
        ;;
    false) #laptop_mode_ac 
        cat /sys/class/backlight/acpi_video0/max_brightness > 
            /sys/class/backlight/acpi_video0/brightness
        ;;
    help) help;;
    *) exit $NA ;;
esac
exit 0

This entry was posted in Technical. Bookmark the permalink.

One Response to Ubuntu: power.d display brightness by AC/Battery mode

  1. rotegras says:

    Thanks! I was long time looking for that.

Leave a Reply to rotegras Cancel reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.