forked from jdpedersen1/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vol.sh
executable file
·70 lines (64 loc) · 2.31 KB
/
vol.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
#!/bin/bash
# You can call this script like this:
# $./volume.sh up
# $./volume.sh down
# $./volume.sh mute
function get_volume {
amixer -D pulse get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
}
function is_mute {
amixer -D pulse get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
}
function send_notification {
DIR=`dirname "$0"`
volume=`get_volume`
# Make the bar with the special character ─ (it's not dash -)
# https://en.wikipedia.org/wiki/Box-drawing_character
#bar=$(seq -s "─" $(($volume/5)) | sed 's/[0-9]//g')
if [ "$volume" = "0" ]; then
icon_name="/usr/share/icons/Faba/48x48/notifications/notification-audio-volume-muted.svg"
$DIR/notify-send.sh "$volume"" " -i "$icon_name" -t 2000 -h int:value:"$volume" -h string:synchronous:"─" --replace=555
else
if [ "$volume" -lt "10" ]; then
icon_name="/usr/share/icons/Faba/48x48/notifications/notification-audio-volume-low.svg"
$DIR/notify-send.sh "$volume"" " -i "$icon_name" --replace=555 -t 2000
else
if [ "$volume" -lt "30" ]; then
icon_name="/usr/share/icons/Faba/48x48/notifications/notification-audio-volume-low.svg"
else
if [ "$volume" -lt "70" ]; then
icon_name="/usr/share/icons/Faba/48x48/notifications/notification-audio-volume-medium.svg"
else
icon_name="/usr/share/icons/Faba/48x48/notifications/notification-audio-volume-high.svg"
fi
fi
fi
fi
bar=$(seq -s "─" $(($volume/5)) | sed 's/[0-9]//g')
# Send the notification
$DIR/notify-send.sh "$volume"" ""$bar" -i "$icon_name" -t 2000 -h int:value:"$volume" -h string:synchronous:"$bar" --replace=555
}
case $1 in
up)
# Set the volume on (if it was muted)
amixer -D pulse set Master on > /dev/null
# Up the volume (+ 5%)
amixer -D pulse sset Master 5%+ > /dev/null
send_notification
;;
down)
amixer -D pulse set Master on > /dev/null
amixer -D pulse sset Master 5%- > /dev/null
send_notification
;;
mute)
# Toggle mute
amixer -D pulse set Master 1+ toggle > /dev/null
if is_mute ; then
DIR=`dirname "$0"`
$DIR/notify-send.sh -i "/usr/share/icons/Faba/48x48/notifications/notification-audio-volume-muted.svg" --replace=555 -u normal "Mute" -t 2000
else
send_notification
fi
;;
esac