Automatically switch power profiles between Balanced and Power Saver based on laptop power status (plugged/unplugged), including on boot and resume — now with cross‑distro support!
power-mode-switcher/
├── README.md # This file
├── install.sh # Cross‑distro installation script
├── uninstall.sh # Uninstallation script
├── LICENSE
└── src/
├── power-mode-switch.sh # Main switching script
├── 99-power-mode.rules # udev rule
└── power-mode.service # systemd service definition
- Debian / Ubuntu / Zorin (APT)
- Arch / Manjaro / EndeavourOS (Pacman)
- Fedora / RHEL / CentOS (DNF / tuned‑ppd)
- A modern GNOME or KDE desktop with
powerprofilesctlsupport bash,udev,systemd(default on all supported distros)- Root or sudo privileges to install/uninstall
-
Clone & enter repo
git clone https://github.com/md8-habibullah/power-mode-switcher.git cd power-mode-switcher -
Make scripts executable
chmod +x install.sh uninstall.sh src/power-mode-switch.sh
-
Run the installer
./install.sh
You’ll see coloured, step‑by‑step output:
- Detects your package manager (
apt,pacman, ordnf) - Installs
power-profiles-daemon(or swaps intuned‑ppdon Fedora ≥ 41) - Copies the switch script, udev rule, and systemd unit into place
- Reloads systemd & udev, then enables all services
- Detects your package manager (
-
Automatic switching
- Plug or unplug your AC adapter → runs automatically
- Suspend & resume → runs on wake
-
Check current profile
powerprofilesctl get
(on Fedora/RHEL with tuned‑ppd you can also run
tuned-adm active) -
Manual invocation
sudo /usr/local/bin/power-mode-switch.sh
In the repo directory:
./uninstall.shThis will:
- Disable & remove the
power-mode.serviceunit - Remove
/etc/udev/rules.d/99-power-mode.rules - Remove
/usr/local/bin/power-mode-switch.sh - Reload systemd & udev rules
-
AC device name If your AC path differs, edit in
src/power-mode-switch.sh:for P in /sys/class/power_supply/ADP* /sys/class/power_supply/AC* /sys/class/power_supply/ACAD*; do … done
-
Enable logging Uncomment in
power-mode-switch.sh:# echo "$(date +'%F %T'): AC=$STATUS → $(powerprofilesctl get)" >> /var/log/power-mode.logEnsure
/var/log/power-mode.logis writable by root. -
Custom profiles Replace
balanced/power-saverwith any profile name supported by your system.
-
No switching on plug/unplug
udevadm monitor --udev
Verify
POWER_SUPPLY_ONLINEevents and that your rule matches the device. -
Service errors on boot/resume
journalctl -u power-mode.service -b systemctl status power-mode.service
-
Permissions Ensure
/usr/local/bin/power-mode-switch.shischmod +xand owned by root.
Supports Debian/Ubuntu, Zorin, Mint, Arch, Manjaro, EndeavourOS, Fedora, CentOS, RHEL and any system with systemd & udev. Created by Md. Habibullah (md8-habibullah)