DEV Community

Brisbane Web Developer
Brisbane Web Developer

Posted on

1 2

Set your laptop into energy save mode with KDE Plasma manually

Summary

  • KDE Plasma often does not detect when I unplug my X1 Extreme Gen 2 (X1E2) recently. I don't know why.

  • And I noticed Docker eats up all the battery by the time I wake up if I did not keep it plugged before going to bed.

  • So I created a shell script to turn things off so that I can run it manually when I unplugged the AC adapter.

Script

  • The important part is the last bit. That bit seems to make KDE Plasma see the state of AC (So the actual cause would be upower.service, not KDE Plasma).

  • Your situation would be different from mine so you can just copy everything at first and then add/remove/amend the lines to suit you.

/usr/local/bin/savebattery
==========
#!/bin/bash

#
# Lower the brightness on monitor
#
echo
echo 2909 > /sys/class/backlight/intel_backlight/brightness
echo -n "Brightness: "; cat /sys/class/backlight/intel_backlight/brightness
echo

#
# Stop and disable the services for Docker
#
systemctl stop docker.service
systemctl disable docker.service
echo
systemctl --no-pager status docker.service | egrep "Loaded:|Active:" | tr -d ' '

systemctl stop docker.socket
systemctl disable docker.socket
echo
systemctl --no-pager status docker.socket | egrep "Loaded:|Active:" | tr -d ' '

echo

#
# Stop and disable the services for Avahi
# - The solution may be "aptitude purge avahi-daemon", but I am disabling it
#   in case I actually need this somehow
#
systemctl stop avahi-daemon.service
systemctl disable avahi-daemon.service
echo
systemctl --no-pager status avahi-daemon.service | egrep "Loaded:|Active:" | tr -d ' '

systemctl stop avahi-daemon.socket
systemctl disable avahi-daemon.socket
echo
systemctl --no-pager status avahi-daemon.socket | egrep "Loaded:|Active:" | tr -d ' '

echo

#
# Disable the network interfaces
#
ip link set docker0 down
ip address | egrep "docker0:"

interface=$(ip address | egrep ": br-" | sed -E 's/^[0-9]: ([^\s:]+).+/\1/')
ip link set $interface down
ip address | egrep ": br-"

echo

#
# Make sure KDE Plasma see AC state properly
#
systemctl restart upower.service
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay