Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 92 lines (82 sloc) 1.67 KB
#!/bin/bash
NAME="paVolume"
BLURB="Pulseaudio volume control"
SOURCE="https://github.com/vonbrownie/homebin/blob/master/paVolume"
sinkMute="pactl set-sink-mute @DEFAULT_SINK@"
sinkVol="pactl set-sink-volume @DEFAULT_SINK@"
showVol="volnoti-show $(pamixer --get-volume)"
scriptDetails() {
cat << _EOF_
NAME
$NAME
SYNOPSIS
$NAME [ options ]
OPTIONS
-h script details
-m toggle volume mute
-u increase volume +10%
-d decrease volume -10%
DESCRIPTION
$BLURB
DEPENDS
pactl - control a running pulseaudio server
pamixer - pulseaudio command line mixer
volnoti - lightweight sound notification
SOURCE
$SOURCE
_EOF_
}
testPath() {
local require=(pactl pamixer volnoti)
for i in ${require[@]}
do
hash $i 2>/dev/null || \
{ echo -e >&2 "I require '$i' but it's not installed.\n"; \
scriptDetails; exit 1; }
done
}
notExceed() {
# Max volume not to exceed 100%
# ('volnoti-show' breaks if <volume> not range 0-100)
if (("$(pamixer --get-volume)" > "100")); then $sinkVol 100%; fi
}
volMute() {
$sinkMute toggle; [[ $(pamixer --get-mute) = true ]] \
&& volnoti-show -m || $showVol
}
volUp() {
$sinkVol +10%; notExceed; $showVol
}
volDown() {
$sinkVol -10%; $showVol
}
runOptions() {
while getopts ":hmud" OPT
do
case $OPT in
h)
scriptDetails
exit 0
;;
m)
volMute
exit 0
;;
u)
volUp
exit 0
;;
d)
volDown
exit 0
;;
*)
echo "Invalid option '-$OPTARG'"
exit 1
;;
esac
done
}
# START
testPath
runOptions "$@"
You can’t perform that action at this time.