#!/bin/bash # =========================================================================== # idle-battery-suspend.sh — Suspend laptop only when on battery # Checks AC power status before suspending. If on AC power, does nothing. # Used by swayidle.service (systemd user service). # =========================================================================== # Only suspend if on battery (AC online = 0) AC_ONLINE=$(cat /sys/class/power_supply/AC/online 2>/dev/null) if [ "$AC_ONLINE" = "0" ]; then systemctl suspend-then-hibernate fi