Created
February 11, 2017 19:10
-
-
Save fedescarpa/30e0228145903e2cbe0df62a714ddab8 to your computer and use it in GitHub Desktop.
Improve battery life
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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