2023-05-21 15:51:52 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-10-10 14:39:26 +02:00
|
|
|
|
2020-10-12 07:15:20 +02:00
|
|
|
set -euo pipefail
|
|
|
|
|
2020-10-10 14:39:26 +02:00
|
|
|
# You can call this script like this:
|
2020-10-10 21:33:08 +02:00
|
|
|
# $./dunst-volume.sh up
|
|
|
|
# $./dunst-volume.sh down
|
|
|
|
# $./dunst-volume.sh mute
|
2020-10-10 14:39:26 +02:00
|
|
|
|
|
|
|
get_volume() {
|
2021-09-02 14:36:26 +02:00
|
|
|
amixer -D pulse get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
|
2020-10-10 14:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
is_mute() {
|
2023-05-21 15:51:52 +02:00
|
|
|
amixer -D pulse get Master | grep '%' | grep -oE '[^ ]+$' | grep off >/dev/null
|
2020-10-10 14:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
send_notification() {
|
|
|
|
volume=$(get_volume)
|
|
|
|
# Make the bar with the special character ─ (it's not dash -)
|
|
|
|
# https://en.wikipedia.org/wiki/Box-drawing_character
|
|
|
|
bar=$(seq -s "─" $(($volume / 5)) | sed 's/[0-9]//g')
|
|
|
|
# Send the notification
|
2020-10-10 22:50:15 +02:00
|
|
|
dunstify -i audio-volume-high -r 2593 -a volume-script "$volume $bar "
|
2020-10-10 14:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
up)
|
2023-05-21 15:51:52 +02:00
|
|
|
# Set the volume on (if it was muted)
|
|
|
|
amixer -D pulse set Master on >/dev/null
|
|
|
|
# Up the volume (+ 5%)
|
|
|
|
amixer -D pulse sset Master 5%+ >/dev/null
|
|
|
|
send_notification
|
|
|
|
;;
|
2020-10-10 14:39:26 +02:00
|
|
|
down)
|
2023-05-21 15:51:52 +02:00
|
|
|
amixer -D pulse set Master on >/dev/null
|
|
|
|
amixer -D pulse sset Master 5%- >/dev/null
|
|
|
|
send_notification
|
|
|
|
;;
|
2020-10-10 14:39:26 +02:00
|
|
|
mute)
|
2023-05-21 15:51:52 +02:00
|
|
|
# Toggle mute
|
|
|
|
amixer -D pulse set Master 1+ toggle >/dev/null
|
|
|
|
if is_mute; then
|
|
|
|
dunstify -i audio-volume-muted -r 2593 -u normal "Mute"
|
|
|
|
else
|
|
|
|
send_notification
|
|
|
|
fi
|
|
|
|
;;
|
2020-10-10 14:39:26 +02:00
|
|
|
esac
|