Automatically switch power profile when plugged in (balanced) and unplugged (power saver) (#4375)

* Set Power Profiles Rules when plugged in (balanced) and unplugged (power-saver)"

* Check for battery presence before installing power profile rules

* Add battery presence check script and update powerprofilesctl rules

* fix indentation

* Simplify power profile rule creation logic
This commit is contained in:
Pierre Olivier Martel
2026-01-29 11:37:18 -05:00
committed by GitHub
parent ec305459f8
commit f78f5b2c2c
4 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
if omarchy-battery-present; then
mapfile -t profiles < <(omarchy-powerprofiles-list)
if [[ ${#profiles[@]} -gt 0 ]]; then
# Default AC profile:
# 3 profiles → performance
# 2 profiles → balanced
# 1 profile → profiles[0]
ac_profile="${profiles[2]:-${profiles[1]:-${profiles[0]}}}"
# Default Battery profile:
# 3 profiles → balanced
# 2 profiles → balanced
# 1 profile → profiles[0]
battery_profile="${profiles[1]:-${profiles[0]}}"
cat <<EOF | sudo tee "/etc/udev/rules.d/99-power-profile.rules"
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="0", RUN+="/usr/bin/powerprofilesctl set $battery_profile"
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="1", RUN+="/usr/bin/powerprofilesctl set $ac_profile"
EOF
sudo udevadm control --reload
sudo udevadm trigger --subsystem-match=power_supply
fi
fi