-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsb-volume
executable file
·44 lines (39 loc) · 973 Bytes
/
sb-volume
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
#!/bin/bash
# soundeffect file path
soundfile="/usr/share/sounds/Yaru/stereo/audio-volume-change.oga"
playsound() {
if [[ -f "$soundfile" ]]; then
paplay "$soundfile"
fi
}
update_blocks() {
pkill -RTMIN+2 i3blocks
}
format_volume() {
local vol="$1"
local is_muted=$(pactl get-sink-mute @DEFAULT_SINK@)
if [[ "$is_muted" == *"yes"* ]]; then
vol="muted"
else
vol=$(echo "$vol" | grep -Po '\d+(?=%)' | head -n 1)
fi
echo "vol: $vol"
}
case "$1" in
up)
playsound
pactl set-sink-volume @DEFAULT_SINK@ +5%
update_blocks ;;
down)
playsound
pactl set-sink-volume @DEFAULT_SINK@ -5%
update_blocks ;;
query)
volume=$(pactl get-sink-volume @DEFAULT_SINK@)
format_volume "$volume" ;;
toggle)
pactl set-sink-mute @DEFAULT_SINK@ toggle
update_blocks ;;
*)
echo "Usage: ./sb-volume [up|down|toggle|query]" ;;
esac