-
Notifications
You must be signed in to change notification settings - Fork 1
/
set-volume
executable file
·75 lines (59 loc) · 1.6 KB
/
set-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
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
#! /bin/sh
XOB=/tmp/xobpipe
if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ] || [ -z "$1" ]; then
cat <<EOF
$ set-volume.sh COMMAND
Set the volume and send a notification.
Commands:
mute: toggle mute
+<n>: raise volume
-<n>: lower volume
Example:
$ set-volume.sh +5
$ set-volume.sh -5
$ set-volume.sh mute
EOF
exit
fi
command -v pulsemixer >/dev/null || { echo "pulsemixer is not installed"; exit 1; }
COMMAND="$1"
get_active_sink() {
if RUNNING_SINKS="$(pactl list sinks short | grep -F 'RUNNING' -m1)"; then
echo $RUNNING_SINKS | tail -n1 | awk '{ print $1 }'
else
case "$(cat /etc/hostname)" in
*x240) echo 1;;
*x270) echo 0;;
*e495) echo 0;;
*) echo 0;;
esac
fi
}
notification() {
PROPS="$(pactl list sinks | grep -F "Sink #$SINK" -A 32)"
MUTE=$(echo $PROPS | grep -F "Mute: no" >/dev/null && echo 0 || echo 1)
VOL="$(echo $PROPS | grep -Po '\d+%' )"
VOL="$(echo $VOL | awk -F % '{print $1}' )"
[ -z "$VOL" ] && VOL=0
echo mute: $MUTE, vol: $VOL
IS_MUTE=""
[ "$MUTE" -eq 1 ] && IS_MUTE=!
if [ -p $XOB ]; then
echo "$VOL$IS_MUTE"
echo "$VOL$IS_MUTE" >$XOB
fi
}
SINK="$(get_active_sink)"
echo "using sink: $SINK"
case "$COMMAND" in
mute) pactl set-sink-mute "$SINK" toggle ;;
+*|-*) pactl set-sink-volume "$SINK" "${COMMAND}%" ;;
*) echo Invalid command, see --help ;;
esac
notification
# MPD=~/scripts/mpd
# if [ "$(cat $MPD/mpd-server-status)" -gt 0 ]; then
# if $MPD/is-mpd-playing; then # nested for performance
# echo ok # control mpd server instead of local volume as long as music is playing
# fi
# fi