-
Notifications
You must be signed in to change notification settings - Fork 9
/
pacvol.sh
executable file
·122 lines (105 loc) · 2.29 KB
/
pacvol.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
# PulseAudio Volume Control Script
# 2010-05-20 - Gary Hetzel <garyhetzel@gmail.com>
#
# BUG: Currently doesn't get information for the specified sink,
# but rather just uses the first sink it finds in list-sinks
# Need to fix this for systems with multiple sinks
#
SINK=0
STEP=1
MAXVOL=65537 # let's just assume this is the same all over
MUTED=0
#MAXVOL=`pacmd list-sinks | grep "volume steps" | cut -d: -f2 | tr -d "[:space:]"`
MUTED=`pacmd list-sinks 0 | grep muted | cut -d ' ' -f 2`
#VOLPERC=`pactl list sinks | awk '/Volume: 0:/ {print substr($3, 1, index($3, "%") - 1)}' | head -n1`
VOLPERC=`pactl list sinks | awk '/Volume: front-left:/ {print substr($5, 1, index($5, "%") - 1)}'`
SKIPOVERCHECK=1
display(){
if [ "$MUTED" = "yes" ]; then
echo "🔇 muted"
elif [ "$VOLPERC" -lt 33 ]; then
echo "🔈 ${VOLPERC}%"
elif [ "$VOLPERC" -lt 66 ]; then
echo "🔉 ${VOLPERC}%"
else
echo "🔊 ${VOLPERC}%"
fi
}
up(){
VOLSTEP="$(( $VOLPERC+$STEP ))";
}
down(){
VOLSTEP="$(( $VOLPERC-$STEP ))";
SKIPOVERCHECK=1
}
max(){
pacmd set-sink-volume $SINK $MAXVOL > /dev/null
}
min(){
pacmd set-sink-volume $SINK 0 > /dev/null
}
overmax(){
SKIPOVERCHECK=1
if [ $VOLPERC -lt 100 ]; then
max;
exit 0;
fi
up
}
mute(){
pacmd set-sink-mute $SINK 1 > /dev/null
}
unmute(){
pacmd set-sink-mute $SINK 0 > /dev/null
}
toggle(){
M=`pacmd list-sinks | grep "muted" | cut -d: -f2 | tr -d "[:space:]"`
if [ $M == "no" ]; then
mute;
else
unmute;
fi
}
case $1 in
up)
up;;
down)
down;;
max)
max
exit 0;;
min)
min
exit 0;;
overmax)
overmax;;
toggle)
toggle
exit 0;;
mute)
mute;
exit 0;;
unmute)
unmute;
exit 0;;
display)
display;
exit 0;;
*)
echo "Usage: `basename $0` [up|down|min|max|overmax|toggle|mute|unmute|display]"
exit 1;;
esac
VOLUME="$(( ($MAXVOL/100) * $VOLSTEP ))"
echo "$VOLUME : $OVERMAX"
if [ -z $SKIPOVERCHECK ]; then
if [ $VOLUME -gt $MAXVOL ]; then
VOLUME=$MAXVOL
elif [ $VOLUME -lt 0 ]; then
VOLUME=0
fi
fi
#echo "$VOLUME: $MAXVOL/100 * $VOLPERC+$VOLSTEP"
pacmd set-sink-volume $SINK $VOLUME > /dev/null
# VOLPERC=`pacmd list-sinks | grep "volume" | head -n1 | cut -d: -f3 | cut -d% -f1 | tr -d "[:space:]"`
#osd_cat -b percentage -P $VOLPERC --delay=1 --align=center --pos bottom --offset 50 --color=green&