Skip to content

Instantly share code, notes, and snippets.

@fedescarpa
Created February 11, 2017 19:10
Show Gist options
  • Save fedescarpa/30e0228145903e2cbe0df62a714ddab8 to your computer and use it in GitHub Desktop.
Save fedescarpa/30e0228145903e2cbe0df62a714ddab8 to your computer and use it in GitHub Desktop.
Improve battery life
#!/bin/bash
battery_level=""
function battery() {
echo $(acpi -b | grep -oE "[0-9][0-9]?%" | grep -oE "[0-9]+")
}
function play_sound() {
paplay /usr/share/sounds/LinuxMint/stereo/window-slide.ogg &
}
notify-send "Battery Life is running!" "Charging: $(battery)%"
while true; do
battery_level=$(battery)
if on_ac_power; then
if [ "$battery_level" -ge "80" ]; then
play_sound
notify-send "Battery is greater than 80%!" "Charging: ${battery_level}%"
fi
else
if [ "$battery_level" -le "40" ]; then
play_sound
notify-send "Battery is lower than 40%!" "Charging: ${battery_level}%"
fi
fi
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment