-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_volume
More file actions
executable file
·97 lines (85 loc) · 2.68 KB
/
Copy pathchange_volume
File metadata and controls
executable file
·97 lines (85 loc) · 2.68 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
#!/bin/sh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2021 Jeremy Brubaker <jbru362@gmail.com>
#
# abstract: change volume
#
# Requires (wpctl | pactl) and dunst
#
# Arbitrary but unique message id for dunst
msg_id=chgvol-$0
if command -v wpctl >/dev/null; then
case "$1" in
mute)
cmd=mute
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
;;
+*|-*)
cmd=adj
sign=$(echo "$1" | cut -c1)
amnt=$(echo "$1" | cut -c2-)
wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ "$amnt$sign"
;;
esac
current_volume=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ |
cut -d' ' -f2 | sed -e 's/^0\.//' -e 's/^0//')
if wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep -q MUTED; then
is_muted=yes
else
is_muted=no
fi
elif command -v pactl >/dev/null; then
default_sink=$(LC_ALL=C pactl list sinks short | \
grep "$(\
pactl info |
grep "Default Sink" |
sed 's/[^:]*: //')" |
cut -f1)
case "$@" in
mute)
pactl set-sink-mute @DEFAULT_SINK@ toggle
;;
+*|-*)
pactl set-sink-volume @DEFAULT_SINK@ "$@"
;;
*) exit 1 ;;
esac
current_volume=$(LC_ALL=C pactl list sinks | \
grep -A9 "Sink #$default_sink" |
grep Volume |
awk '{print $5}' |
tr -dc '[:digit:]')
is_muted=$(LC_ALL=C pactl list sinks | \
grep -A9 "Sink #$default_sink" | \
grep Mute | \
awk '{print $2}')
else
printf '%s\n' 'Neither wpctl or pactl found' >&2
exit 1
fi
if [ "$is_muted" = 'yes' ] || [ "$current_volume" = '0' ]; then
icon=audio-volume-muted
else
icon=audio-volume-high
fi
if [ "$cmd" = 'mute' ] && [ "$is_muted" = 'yes' ]; then
dunstify -a "changeVolume" -u low -i "$icon" \
-h "string:x-dunst-stack-tag:$msg_id" "Volume muted"
else
dunstify -a "changeVolume" -u low -i "$icon" \
-h "string:x-dunst-stack-tag:$msg_id" \
-h int:value:"$current_volume" "Volume: ${current_volume}%"
fi