Skip to content

Instantly share code, notes, and snippets.

@pavanyogi
Last active September 21, 2022 12:08
Show Gist options
  • Save pavanyogi/681fa31cd2fce0b1c8123f42e98f2053 to your computer and use it in GitHub Desktop.
Save pavanyogi/681fa31cd2fce0b1c8123f42e98f2053 to your computer and use it in GitHub Desktop.
set battery full charge alert notification with sound play
#!/bin/bash
# sudo apt install acpi
# cd
# wget https://gist.githubusercontent.com/pavanyogi/681fa31cd2fce0b1c8123f42e98f2053/raw/56ef38e90e6d6bdcacb1aba23b57b7ced8838699/battery-full.sh
# sudo chmod -v +x battery-full.sh
# sudo mv -v battery-full.sh /usr/local/bin
# add the command to startup applications
# /usr/local/bin/battery-full.sh
COUNTER=10
while true; do
export DISPLAY=:0.0
battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
if on_ac_power; then #check if AC is plugged in
if [ $battery_level -ge 90 ]; then #check if the battery level is over 90%
notify-send -u critical "Please unplug your AC adapter" "Battery level: ${battery_level}% (charged above 90%)" -i battery-full-charged
while [[ $COUNTER -ge 0 ]]; do
battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
if on_ac_power; then
COUNTER=$[COUNTER - 1]
paplay /usr/share/sounds/ubuntu/ringtones/Alarm\ clock-[AudioTrimmer.com].ogg
fi
done
fi
else
if [ $battery_level -le 25 ]; then #check if the battery level is over 90%
notify-send -u critical "Please plugin your AC adapter" "Battery level: ${battery_level}% (charge less than 25%)" -i battery-full-charged
while [[ $COUNTER -ge 0 ]]; do
battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
if on_ac_power; then
sleep 1
else
COUNTER=$[COUNTER - 1]
paplay /usr/share/sounds/ubuntu/ringtones/Alarm\ clock-[AudioTrimmer.com].ogg
fi
done
fi
fi
sleep 100 #wait for 300 seconds before checking again
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment