Last active
May 22, 2022 08:38
-
-
Save imambungo/b8bc1292a82ad9471510d2a777c0e5c1 to your computer and use it in GitHub Desktop.
ultraman low battery
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 | |
low_battery_percent=20 | |
low_remaining_minute=5 # max is 60 | |
low_battery_sound_file="~/bin/ultramanCTSE.mp3" | |
full_battery_sound_file="~/bin/full_battery.wav" | |
max_sound_length_in_second=10 # max is 60 | |
# Dependencies & Troubleshooting: https://superuser.com/a/308441/943615 | |
# suara macet setelah 1 detik kalo ga pake ini, notify-send jg ngga jalan | |
# khusus ubuntu? btw bisa lewat cron file (crontab -e) | |
# https://stackoverflow.com/a/53598510/9157799 | |
# export XDG_RUNTIME_DIR="/run/user/$uid" | |
max_capacity=`acpi -i | awk 'END{print $NF}'` | |
# use nested square brackets for string | |
if [[ `acpi -b | awk ' {print $3}'` == "Discharging," ]] | |
then | |
battery=`acpi -b | awk '{print $4-0}'` | |
remaining_time=`acpi -b | awk '{print $5}'` | |
hour=`echo $remaining_time | awk -F ":" '{print $1-0}'` | |
minute=`echo $remaining_time | awk -F ":" '{print $2-0}'` | |
if [ $battery -le $low_battery_percent ] || [ $hour -eq 0 ] && [ $minute -lt $low_remaining_minute ] | |
then | |
notify-send "battery is low: $battery%" "battery health: $max_capacity\n$remaining_time remaining" | |
play "$low_battery_sound_file" trim 0 $max_sound_length_in_second | |
fi | |
else | |
if [ `acpi -b | awk ' { print ($5)-0}'` -eq 100 ] | |
then | |
notify-send "battery is full" "battery health: $max_capacity" | |
play "$full_battery_sound_file" trim 0 $max_sound_length_in_second | |
fi | |
fi |
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
# non ubuntu | |
# * * * * * ~/bin/battery_alert.sh | |
# https://crontab.guru/ | |
* * * * * XDG_RUNTIME_DIR=/run/user/$(id -u) ~/bin/battery_alert.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
acpi
is deprecated. Find an alternative here and here.