-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvol.sh
executable file
·79 lines (60 loc) · 1.74 KB
/
vol.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
#
#---
# Increases/decreases/(un)mutes the volume (uses pulseaudio)
#---
# Fernando Carmona Varo
#
# Volume 65536 (0x10000) is normal max, greater values will amplify the audio signal (with clipping).
# A multiplier can be specified here
multiplier=3
percent=$1
if [ -z $percent ]
then
echo "usage: vol.sh <+XX|-XX|mute>"
exit
fi
if [ "$1" = "mute" ] # toggle mute
then
pactl set-sink-mute @DEFAULT_SINK@ toggle
exit
fi
default_sink=$(pacmd dump | sed -n 's/set-default-sink \(.*\)/\1/p')
current_vol=$(pacmd dump | sed -n "s/set-sink-volume $default_sink \(.*\)/\1/p")
if [ "$current_vol" ]
then
# Don't apply multiplier when volume is less than 100%
if [ $((current_vol*100/0x10000)) -lt 100 ]
then
max=$((0x10000))
else
max=$((multiplier * 0x10000))
fi
set_vol=$((current_vol + (percent * max/100)))
#set_vol=$((current_vol + (percent * 100)))
if [ $((set_vol)) -lt $((0x0)) ]
then
echo "Volume can't be set lower"
set_vol=$((0x0))
elif [ $((set_vol)) -gt $((max)) ]
then
echo "Volume can't be set higher"
set_vol=$((max))
fi
[ "$set_vol" = "$current_vol" ] && exit
display_vol=$((set_vol * multiplier * 100/max))
pactl set-sink-volume @DEFAULT_SINK@ $set_vol
# notify with osd if available
hash osd_cat 2>$- && {
pkill osd_cat
osd_cat -O 3 -o 12 -c white -A center -d 1 -f "-*-*-*-*-*-*-*-*-*-*-*-*-*" \
-b percentage -P $((set_vol * 100/max)) -T $((set_vol*100/0x10000))
} &
else
echo "Couldn't get current volume!"
display_vol="${percent}%"
pactl set-sink-volume @DEFAULT_SINK@ ${percent}%
fi
# notify about the volume change in dwm
xsetroot -name "volume: $display_vol" && sleep 1 && dwm.sh update &
echo $display_vol