#!/usr/bin/bash # ABOUTME: Toggles battery conservation mode between 80% and 100% charge limit. # ABOUTME: Reads sysfs as user, dispatches the privileged write via pkexec. THRESHOLD_FILE="/sys/class/power_supply/BAT0/charge_control_end_threshold" CONSERVATION_LIMIT=80 [[ -f "$THRESHOLD_FILE" ]] || exit 1 CURRENT=$(cat "$THRESHOLD_FILE") [[ "$CURRENT" =~ ^[0-9]+$ ]] || exit 1 if [[ "$CURRENT" -le "$CONSERVATION_LIMIT" ]]; then NEW=100 else NEW="$CONSERVATION_LIMIT" fi pkexec /usr/bin/moonarch-batsaver-apply "$NEW" || exit 1 # Signal Waybar to refresh the batsaver module (SIGRTMIN+9) pkill -RTMIN+9 waybar