-
Notifications
You must be signed in to change notification settings - Fork 39
/
notify-volume.sh
executable file
·52 lines (43 loc) · 1.2 KB
/
notify-volume.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
49
50
51
52
#!/bin/bash
# volume control (up/down/mute/unmute/toggle) + notification
# duration in ms
duration=1500
notify () {
# get volume level
percent=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '\d+(?=%)' | head -n 1)
# check if muted, set title
if [[ $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: yes" ]]; then
title="Volume muted"
else
title="Volume"
fi
# create fancy bar
f=$((percent/10))
e=$((10-f))
fchars='◼◼◼◼◼◼◼◼◼◼'
echars='◻◻◻◻◻◻◻◻◻◻'
bar="${fchars:0:f}${echars:0:e} $percent%"
notify-send --app-name=VolumeNotification --expire-time="$duration" --urgency=low "$title" "$bar"
}
# redirect stdout of this script to /dev/null
exec > /dev/null
case "$1" in
up)
pactl set-sink-volume @DEFAULT_SINK@ +5%
pactl set-sink-mute @DEFAULT_SINK@ 0
;;
down)
pactl set-sink-volume @DEFAULT_SINK@ -5%
pactl set-sink-mute @DEFAULT_SINK@ 0
;;
mute)
pactl set-sink-mute @DEFAULT_SINK@ 1
;;
unmute)
pactl set-sink-mute @DEFAULT_SINK@ 0
;;
toggle)
pactl set-sink-mute @DEFAULT_SINK@ toggle
;;
esac
notify