-
Notifications
You must be signed in to change notification settings - Fork 1
/
Volume.sh
executable file
·111 lines (104 loc) · 4.21 KB
/
Volume.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
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
#!/bin/bash
# Volume control script for https://github.com/Naereen/GMusicBrowser-FullScreen-WebApp
# MIT Licence, https://lbesson.mit-license.org/.
# A bash script to control amixer volume through the command line.
# Colors
escp="\033["
blue="${escp}01;34m"
red="${escp}01;31m"
green="${escp}01;32m"
yellow="${escp}01;35m"
white="${escp}01;37m"
[ -f ~/.color.sh ] && . ~/.color.sh
volume() {
e=$(amixer sget 'Master',0 | grep 'Mono:' | grep -o '[0-9]*%')
echo "${e}"
}
volume_value() {
e=$(volume)
echo "${e%\%}"
}
if [ "$*" = "" ]; then
# Simply print the volume !
echo -e "${green}Information about the volume : ${blue}$(amixer sget 'Master',0 | grep \"Mono:\")${white}.\n\tVolume=${red}$(volume)${white}"
notify-send --icon=sound "Volume.sh" "Information about the volume : $(amixer sget 'Master',0 | grep \"Mono:\")."
exit 0
fi
# Argument testing
for arg in "$@"; do
case "$arg" in
-h|--help)
echo -e "${red}Volume.sh [OPTIONS] [COMMAND]${white}\n\n\
A bash script to control the volume (with amixer) through the command line.\n\
All command, except for value, print useful colored infos, and notify the user (use notify-send).\n\
${blue}OPTIONS${white}:\n\
=========\n\
${yellow}-h, --help${white} Print this help,\n\
${blue}COMMAND${white}:\n\
=========\n\
${yellow}value${white} Return the numerical value of the volume (as a percentage : useful with other scripts),\n\
${yellow}notify${white} Print and notify informations about the Main volume (value, percentage, gain, on/off),\n\
${yellow}up${white} Increase the volume by 5%,\n\
${yellow}down${white} Decrease the volume by 5%,\n\
${yellow}mute${white} Mute (turn off),\n\
${yellow}unmute${white} Unmute (turn on) ${red} FIXME : doesn't work yet ${white},\n\
${yellow}VALUE|PER${white} Set the volume to VALUE, or to the percentage PER (example: 'Volume.sh 30%', or 'Volume.sh 20'),\n\
${blue}COPYRIGHTS${white}:\n\
===========\n\
${red}Lilian BESSON (C) 11-01-2013${white}\n\
Check out the last version online : ${green}http://perso.crans.org/besson/bin/Volume.sh${white}"
exit 0
;;
value*)
volume_value
exit 0
;;
notify*)
echo -e "${green}Information about the volume : ${blue}$(amixer sget 'Master',0 | grep \"Mono:\")${white}.\n\tVolume=${red}$(volume)${white}"
notify-send --icon=sound "Volume.sh" "Information about the volume : $(amixer sget 'Master',0 | grep \"Mono:\")."
exit 0
;;
mute*)
echo -e "${green}Mutting the volume${white} (command mute)..."
amixer sset 'Master',0 0% # | grep "Mono:"
## notify-send --icon=sound "Volume.sh" "Information about the volume : $(amixer sget 'Master',0 | grep \"Mono:\") (after mutting)."
;;
unmute*)
echo -e "${green}Unmutting the volume${white} (command unmute)..."
#vol=$(volume_value)
#amixer sset 'Master',0 unmute 2> /dev/null > /dev/null
#amixer sset 'Master',0 on 2> /dev/null > /dev/null
amixer sset 'Master',0 20% # | grep "Mono:"
# amixer sset 'Master',0 -- -42.75dB | grep "Mono:"
## notify-send --icon=sound "Volume.sh" "Information about the volume : $(amixer sget 'Master',0 | grep \"Mono:\") (after unmutting)."
;;
down*|-|moins*)
vol=$(volume_value)
newvol=$((vol-5))
if [ "$newvol" -lt 0 ]; then
echo -e "${red}Volume negative...${white}"
newvol=0
fi
echo -e "${green}Decreasing the volume${white} by 5% ($vol -> $newvol) (command down)..."
amixer sset 'Master',0 $newvol% | grep "Mono:"
## notify-send --icon=sound "Volume.sh" "Information about the volume : $(amixer sget 'Master',0 | grep \"Mono:\") (after decreasing by 5%)."
;;
up*|+*|plus*)
vol=$(volume_value)
newvol=$((vol+5))
if [ "$newvol" -gt 100 ]; then
echo -e "${red}Volume negative...${white}"
newvol=0
fi
echo -e "${green}Increasing the volume${white} by 5% ($vol -> $newvol) (command up)..."
amixer sset 'Master',0 $newvol% | grep "Mono:"
## notify-send --icon=sound "Volume.sh" "Information about the volume : $(amixer sget 'Master',0 | grep \"Mono:\") (after increasing by 5%)."
;;
*)
echo -e "${green}Setting the volume to ${blue}$arg${white} (command PER% or VAL)..."
amixer sset 'Master',0 "$arg" | grep "Mono:"
notify-send --icon=sound "Volume.sh" "Information about the volume : $(amixer sget 'Master',0 | grep \"Mono:\") (after running $arg)."
;;
esac
done
# DONE