Skip to content

Instantly share code, notes, and snippets.

@j1cs
Created March 25, 2015 02:33
Show Gist options
  • Save j1cs/3cc2e824fa834395b9a2 to your computer and use it in GitHub Desktop.
Save j1cs/3cc2e824fa834395b9a2 to your computer and use it in GitHub Desktop.
Notificar batería baja
#!/bin/bash
# must install notification-daemon package
# low battery in %
LOW_BATTERY="15"
# critical battery in % (execute action)
CRITICAL_BATTERY="10"
# action
ACTION="/sbin/poweroff"
# display icon
ICON="/usr/share/icons/gnome/32x32/status/battery-caution.png"
# path to battery /sys
BATTERY_PATH="/sys/class/power_supply/BAT0/"
if [ -e "$BATTERY_PATH" ]; then
BATTERY_ON=$(cat $BATTERY_PATH/status)
if [ "$BATTERY_ON" == "Discharging" ]; then
CURRENT_BATTERY=$(cat $BATTERY_PATH/capacity)
if [ "$CURRENT_BATTERY" -lt "$CRITICAL_BATTERY" ]; then
$($ACTION)
elif [ "$CURRENT_BATTERY" -lt "$LOW_BATTERY" ]; then
notify-send -i "$ICON" "Battery IS low - $CURRENT_BATTERY %."
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment