Advertisement
Rnery

Battery Status

Mar 5th, 2022 (edited)
551
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.98 KB | Source Code | 1 0
  1. #!/usr/bin/env bash
  2.  
  3. export DISPLAY=:0.0
  4. AC_ADAPTER=$(acpi -a | cut -d' ' -f3 | cut -d- -f1)
  5. BATTERY_LEVEL=$(acpi -b | grep -P -o '[0-9]+(?=%)')
  6.  
  7. while true
  8. do
  9.     if [ "$AC_ADAPTER" == "on" ]; then
  10.         if [ "$BATTERY_LEVEL" -ge 75 ]; then
  11.             while true
  12.             do
  13.                 notify-send -u critical "Despluge o seu adaptador!" "Bateria level: ${BATTERY_LEVEL}% (charged above 75%)" -i battery-full-charged;
  14.                 if [ "$AC_ADAPTER" == "off" ]; then
  15.                     break
  16.                 fi
  17.             done
  18.         fi
  19.     else
  20.         #check if the battery level is less than 25%
  21.         if [ "$BATTERY_LEVEL" -lt 25 ]; then
  22.             while true
  23.             do
  24.                 notify-send -u critical "Plug seu AC adapter" "Level da Bateria: ${BATTERY_LEVEL}% (charge below 25%)" -i battery-caution;
  25.                 if [ "$AC_ADAPTER" == "on" ]; then
  26.                     break
  27.                 fi
  28.             done
  29.         fi
  30.     fi
  31. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement