I38/scripts/battery_alert.sh

37 lines
2.3 KiB
Bash
Raw Permalink Normal View History

#!/bin/sh
# This file is part of I38.
# I38 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
# I38 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with I38. If not, see <https://www.gnu.org/licenses/>.
if ! command -v acpi &> /dev/null ; then
exit 0
fi
while : ; do
acpi -b | awk -F'[,:%]' '{print $2, $3}' | {
read -r status capacity
if [[ "$status" == "Discharging" ]] && [[ "$capacity" -le 15 ]] && [[ "$capacity" -gt 10 ]]; then
play -qV0 "|sox -n -p synth saw E2 fade 0 0.25 0.05" "|sox -n -p synth saw E2 fade 0 0.25 0.05" norm -7
spd-say -P important "Battery $capacity percent."
elif [[ "$status" == "Discharging" ]] && [[ "$capacity" -le 10 ]] && [[ "$capacity" -gt 5 ]]; then
play -qV0 "|sox -n -p synth saw E2 fade 0 0.25 0.05" "|sox -n -p synth saw E2 fade 0 0.25 0.05" norm -7
spd-say -P important "Battery $capacity percent."
elif [[ "$status" == "Discharging" ]] && [[ "$capacity" -lt 5 ]]; then
play -qV0 "|sox -np synth sq C#5 sq D#5 sq F#5 sq A5 sq C#6" remix - fade 0 5.5 5 pitch -400
spd-say -P important "Battery $capacity percent."
fi
}
sleep 5m
done
exit 0