From f78f5b2c2c333c4d556f8b7fe199019d8bab9d94 Mon Sep 17 00:00:00 2001 From: Pierre Olivier Martel Date: Thu, 29 Jan 2026 11:37:18 -0500 Subject: [PATCH] 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 --- bin/omarchy-battery-present | 10 +++++++++ install/config/all.sh | 1 + install/config/powerprofilesctl-rules.sh | 26 ++++++++++++++++++++++++ migrations/1769566732.sh | 3 +++ 4 files changed, 40 insertions(+) create mode 100755 bin/omarchy-battery-present create mode 100755 install/config/powerprofilesctl-rules.sh create mode 100755 migrations/1769566732.sh diff --git a/bin/omarchy-battery-present b/bin/omarchy-battery-present new file mode 100755 index 00000000..9d859c3c --- /dev/null +++ b/bin/omarchy-battery-present @@ -0,0 +1,10 @@ +#!/bin/bash + +for bat in /sys/class/power_supply/BAT*; do + [[ -r "$bat/present" ]] && + [[ "$(cat "$bat/present")" == "1" ]] && + [[ "$(cat "$bat/type")" == "Battery" ]] && + exit 0 +done + +exit 1 diff --git a/install/config/all.sh b/install/config/all.sh index f7a1097b..f4ea88ba 100644 --- a/install/config/all.sh +++ b/install/config/all.sh @@ -19,6 +19,7 @@ run_logged $OMARCHY_INSTALL/config/fast-shutdown.sh run_logged $OMARCHY_INSTALL/config/sudoless-asdcontrol.sh run_logged $OMARCHY_INSTALL/config/input-group.sh run_logged $OMARCHY_INSTALL/config/omarchy-ai-skill.sh +run_logged $OMARCHY_INSTALL/config/powerprofilesctl-rules.sh run_logged $OMARCHY_INSTALL/config/hardware/network.sh run_logged $OMARCHY_INSTALL/config/hardware/set-wireless-regdom.sh run_logged $OMARCHY_INSTALL/config/hardware/fix-fkeys.sh diff --git a/install/config/powerprofilesctl-rules.sh b/install/config/powerprofilesctl-rules.sh new file mode 100755 index 00000000..e1b4da91 --- /dev/null +++ b/install/config/powerprofilesctl-rules.sh @@ -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 <