-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchvol
executable file
·75 lines (66 loc) · 1.73 KB
/
chvol
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
# Change pulseaudio volume and optionally show notification
#
# Requirements:
# pulseaudio
# ponymix
# notify-send (libnotify) (optional)
# Set shell options
set -ef
# Settings:
# notification timeout
timeout=500
# programm names
NOTIFY="notify-send"
# display help screen
usage() {
echo "Usage: $0 [-h | --help] [-n] [-s FILE] VOLUME_SETTING"
echo " -n Display notifiction"
echo " -s Play a sound when changing volume"
echo " -h, --help Show this message"
}
# initialize variables
notification=
sound_file=
vol_setting=
curr_volume=
setting_mode=
# parse commandline parameters
[ "$#" -eq "0" ] && usage && exit 1
while [ "$#" -gt "0" ]; do
case "$1" in
-n) notification=1;;
-s) sound_file="$2"; shift;;
-h|--help) usage; exit 0;;
+*) vol_setting="${1#+}"
setting_mode="plus";;
-*) vol_setting="${1#-}"
setting_mode="minus";;
mute|unmute|toggle)
setting_mode="$1";;
*) vol_setting="$1"
setting_mode="absolute";;
esac
shift
done
case "$setting_mode" in
mute|unmute|toggle)
ponymix "$setting_mode" 2>&1 >/dev/null;;
plus)
ponymix increase "$vol_setting" 2>&1 >/dev/null;;
minus)
ponymix decrease "$vol_setting" 2>&1 >/dev/null;;
absolute)
ponymix set-volume "$vol_setting" 2>&1 >/dev/null;;
esac
# get volume
curr_volume="$(ponymix get-volume)"
[ -n "$sound_file" ] && paplay "$sound_file"
if [ -n "$notification" ]; then
# Send notification; check whether the device is muted or not.
if ponymix is-muted; then
$NOTIFY -t $timeout -u low -h "int:value:$curr_volume" "Pulseaudio" "Volume [MUTE]"
else
$NOTIFY -t $timeout -u low -h "int:value:$curr_volume" "Pulseaudio" "Volume"
fi
fi