-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsubs-volume
More file actions
executable file
·39 lines (32 loc) · 858 Bytes
/
subs-volume
File metadata and controls
executable file
·39 lines (32 loc) · 858 Bytes
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
#!/usr/bin/env bash
#
# Script to subscribe and notify for volume changes
#
current_vol() {
pactl get-sink-volume ${@:-\@DEFAULT_SINK\@} | grep -Po '\d+(?=%)' | head -n 1
}
notify_vol() {
local volume=muted
if [[ $2 -gt 63 ]]; then
level=high
elif [[ $2 -le 63 && $2 -gt 33 ]]; then
level=medium
elif [[ $2 -gt 0 ]]; then
level=low
fi
notify-send -p -r $1 -i "audio-volume-$level" -h "int:value:$2" "Volume"
}
main() {
local sink=$1
local vol=$(current_vol $sink)
local last_volume=$vol
local notify_id=0
pactl subscribe | grep --line-buffered -E "chan.*sink " | while read -r buf; do
vol=$(current_vol $sink)
if [[ "$last_volume" != "$vol" ]]; then
last_volume=$vol
notify_id=$(notify_vol $notify_id $vol)
fi
done
}
main "$@"