-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume-notif.sh
executable file
·49 lines (41 loc) · 985 Bytes
/
volume-notif.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
show_volume_notification() {
volume=$(pactl get-sink-volume @DEFAULT_SINK@ | awk '{print $5}' | tr -d '%')
muted=$(pactl get-sink-mute @DEFAULT_SINK@ | awk '{print $2}')
if [ "$muted" == "yes" ]; then
notify-send -r 2540 -u low "Volume: Muted"
else
notify-send -r 2540 -u low "Volume: $volume%"
fi
}
volume_up() {
pactl set-sink-volume @DEFAULT_SINK@ +5%
show_volume_notification
}
volume_down() {
pactl set-sink-volume @DEFAULT_SINK@ -5%
show_volume_notification
}
mute() {
pactl set-sink-mute @DEFAULT_SINK@ toggle
show_volume_notification
}
# Subscribe to changes in the sink volume and mute status
pactl subscribe | while read -r event; do
if echo "$event" | grep -q "sink #"; then
show_volume_notification
fi
done &
# Trap SIGTERM and SIGINT signals to kill the pactl subscribe process
trap "pkill -f 'pactl subscribe'" EXIT
case $1 in
up)
volume_up
;;
down)
volume_down
;;
mute)
mute
;;
esac