Ubuntu – Can the settings be customized automatically when I boot on battery power

batterypower-managementscripts

Is it possible to tweak settings if and only if the computer starts on battery power?

Why?

I usually work without battery, but when I use a battery I want it to last as long as possible. For that purpose I use little tweaks (granola for minimal power consumption, switching off wifi and bluetooth, and brightness settings).

What?

Whenever I boot my laptop on battery I have to manually tweak all these settings. In the beginning that was OK, but now I want these tweaks to be done automatically. What I want to be tweaked automatically when booting on battery power is

  1. setting the laptop in flight mode (no wifi nor bluetooth)

  2. dimming the screen to 50%

  3. disabling all usb inputs (I often leave a few things in usb slots, but I do not want them activated)

  4. set the power mode in granola to minimal consumption (this needs sudo).

Any ideas? A script that runs automatically when logging in on battery? Anything?

Best Answer

  • You can insert your custom battery-saver commands to an executable file like this under folder "/etc/pm/power.d":

    #!/bin/bash
    if on_ac_power; then
        : # Do nothing
    else
        rfkill block bluetooth # Turn OFF bluetooth
    fi
    exit 0
    

    You can see a list of other options using PowerTOP utility.