On GNOME with power-profiles-daemon, I wanted the power profile to switch between power-saver and performance based on AC power or battery. The solution is to let udev react to POWER_SUPPLY_ONLINE changes and call powerprofilesctl directly.
Put the following rules in /etc/udev/rules.d/99-power-profile-switch.rules:
$ sudo tee /etc/udev/rules.d/99-power-profile-switch.rules >/dev/null <<'EOF'
# AC plugged in
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ENV{POWER_SUPPLY_ONLINE}=="1", ACTION=="change", RUN+="/usr/bin/powerprofilesctl set performance"
# On battery
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ENV{POWER_SUPPLY_ONLINE}=="0", ACTION=="change", RUN+="/usr/bin/powerprofilesctl set power-saver"
EOF
Reload udev and trigger the change:
$ sudo udevadm control --reload-rules
$ sudo udevadm trigger --subsystem-match=power_supply
Verify
Unplug and plug the AC adapter back in, then check the active profile:
$ powerprofilesctl get
| # | Наименование новости | Тональность | Информативность | Дата публикации |
|---|---|---|---|---|
| 1 | apm - Agent Package Manager | 0 | 10 | 02-06-2026 |
| 2 | Клавиатура Panteon T24 Pro самопроизвольно переключет раскладку | 0 | 5 | 22-03-2026 |
| 3 | Auto Land Hover MFD | 0 | 10 | 07-08-2026 |
| 4 | 0 | 0 | 24-03-2026 | |
| 5 | 0 | 0 | 25-05-2026 | |
| 6 | 0 | 5 | 25-05-2026 | |
| 7 | 0 | 0 | 05-05-2026 | |
| 8 | 0 | 0 | 24-10-2018 | |
| 9 | 0 | 0 | 26-10-2018 | |
| 10 | How can I force Dark mode for all users and disable theme variation switching? | 0 | 10 | 17-08-2026 |