-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchange-volume
More file actions
executable file
·128 lines (112 loc) · 2.2 KB
/
Copy pathchange-volume
File metadata and controls
executable file
·128 lines (112 loc) · 2.2 KB
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
123
124
125
126
127
128
#!/usr/bin/env bash
# author | cherrynoize
# https://github.com/cherrynoize
# available commands are
# --------
# | up |
# | down |
# | mute |
# --------
ctl=Master
icon_on=
icon_off=
# delta value
step=5%
# notification duration in seconds
#duration=2
# notification id
#nid=100
# command to turn on control
on_cmd=on
function get_volume {
amixer -D pulse get "$ctl" | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
}
function set_volume {
amixer -D pulse sset "$ctl" "$1" > /dev/null || exit 2
send_notification
}
function is_mute {
amixer -D pulse get "$ctl" | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
}
function mute {
amixer -D pulse set "$ctl" mute > /dev/null
send_notification
}
function unmute {
amixer -D pulse set "$ctl" unmute > /dev/null
send_notification
}
function toggle_mute {
amixer -D pulse set "$ctl" toggle > /dev/null
send_notification
}
function send_notification {
if [ -z "$quiet" ]; then
volume="$(get_volume)"
volume=$((volume*98/100)) # Resize to fit notification on 100%
if is_mute; then
#dunstify -a muteVolume --replace="$nid" -t ${duration}000 -u normal "$icon_off Mute"
notify-percent -a changeVolume -m compact "$volume" "$icon_off"
else
notify-percent -a changeVolume -m compact "$volume" "$icon_on"
fi
fi
}
while [ -n "$1" ]; do
case "$1" in
mic)
ctl=Capture
icon_on=
icon_off=
on_cmd=cap
;;
-q|--quiet)
quiet=1
;;
-*)
echo "unknown option: $1"
exit 1
;;
*)
if [ -n "$arg" ]; then
echo "error: too many commands: $cmd $1"
exit 1
elif [ -n "$cmd" ]; then
arg="$1"
else
cmd=$1
fi
;;
esac
shift
done
case "$cmd" in
"")
send_notification
;;
up)
# Turn volume on
amixer -D pulse set "$ctl" "$on_cmd" > /dev/null || exit 2
[ -z "$arg" ] && arg="$step"
set_volume "$arg"+
;;
down)
[ -z "$arg" ] && arg="$step"
set_volume "$arg"-
;;
mute)
mute
;;
unmute)
unmute
;;
toggle)
toggle_mute
;;
*)
set_volume "$cmd" || {
echo "unknown command: $cmd"
exit 1
}
;;
esac