From 9b539d48aba229913f2bb5ddeb640c14d36c56e3 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Wed, 11 Oct 2023 19:39:26 -0400 Subject: [PATCH] Battery alert script added for laptops. Provides both speech and sound alerts. --- i38.sh | 1 + scripts/battery_alert.sh | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 scripts/battery_alert.sh diff --git a/i38.sh b/i38.sh index 96853b2..1fd1c9c 100755 --- a/i38.sh +++ b/i38.sh @@ -637,6 +637,7 @@ if command -v remind &> /dev/null && command -v notify-send &> /dev/null ; then echo "exec_always --no-startup-id $(command -v remind) -z '-k:${HOME}/.config/i3/scripts/reminder.sh %s &' ${HOME}/.reminders < /dev/null > /dev/null 2>&1" touch ~/.reminders fi +exec_always --no-startup-id ${i3Path}/scripts/sound.py if [[ $dex -eq 0 ]]; then echo '# Start XDG autostart .desktop files using dex. See also' echo '# https://wiki.archlinux.org/index.php/XDG_Autostart' diff --git a/scripts/battery_alert.sh b/scripts/battery_alert.sh new file mode 100755 index 0000000..467417e --- /dev/null +++ b/scripts/battery_alert.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +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