Skip to content

Instantly share code, notes, and snippets.

@DanielFGray
Last active March 6, 2020 23:26
Show Gist options
  • Save DanielFGray/f2683d7e8dc6d6760da5adab012bb070 to your computer and use it in GitHub Desktop.
Save DanielFGray/f2683d7e8dc6d6760da5adab012bb070 to your computer and use it in GitHub Desktop.
alarm
#!/usr/bin/env bash
declare loud=0
declare urgent
declare old_volume
declare old_volume
cleanup() {
set_volume "$old_volume"
}
trap cleanup exit SIGHUP SIGINT SIGTERM SIGQUIT SIGABRT
bground() {
("$@" &> /dev/null &)
}
get_volume() {
pactl list sinks | awk '/Volume:/{print $5; exit}'
}
set_volume() {
pactl set-sink-volume 0 "$1"
}
export -f set_volume
sounds() {
local xt ll
if (( loud )); then
set_volume '50%'
else
set_volume '20%'
fi
xterm -class dialog -geometry 220x60 -display :0 -e "figlet -t '$1' && mpv ${urgent:+--loop=inf} '$sound' ${urgent:+--loop=inf}" &
xt=$!
if (( urgent )); then
while :; do
sleep 10
set_volume '+2%'
pactl set-sink-mute 0 false
done &
ll=$!
fi
wait -f $xt
kill $ll
}
old_volume=$(get_volume)
sound=~/Downloads/Store_Door_Chime-Mike_Koenig-570742973.mp3 # http://soundbible.com/1599-Store-Door-Chime.html
OPTERR=0
while getopts 'uL' opt; do
case "$opt" in
u) sound=~/Downloads/Sunday\ Church\ Ambiance-SoundBible.com-974744686.wav # http://soundbible.com/1264-Sunday-Church-Ambiance.html
urgent=1 ;;
L) loud=1 ;;
t) sound=~/Downloads/Loud_Alarm_Clock_Buzzer-Muk1984-493547174.mp3 # http://soundbible.com/2061-Loud-Alarm-Clock-Buzzer.html
urgent=1 ;;
esac
done
shift $(( OPTIND - 1 ))
unset opt OPTARG OPTIND
(( $# > 0 )) && notify-send ${urgent:+-u critical} "$@"
sounds "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment