2017-01-24 01:46:57 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# finds the active sink for pulse audio and increments the volume. useful when you have multiple audio outputs and have a key bound to vol-up and down
|
|
|
|
# Taken from http://customlinux.blogspot.fr/2013/02/pavolumesh-control-active-sink-volume.html
|
|
|
|
# and slightly adapted by lhark to work with notify-send
|
|
|
|
|
2019-04-27 02:58:52 +00:00
|
|
|
notify='dunst' # no/yes/dunst
|
2017-01-24 01:46:57 +00:00
|
|
|
notiftime='400'
|
2019-04-27 02:58:52 +00:00
|
|
|
notifid='42'
|
2017-06-15 17:32:41 +00:00
|
|
|
inc='2'
|
2017-01-24 01:46:57 +00:00
|
|
|
capvol='yes'
|
|
|
|
maxvol='200'
|
|
|
|
autosync='no'
|
|
|
|
|
|
|
|
main_sink=$(pacmd list-sinks |awk '/* index:/{print $3}')
|
|
|
|
active_sinks=$(pacmd list-sinks |awk '/index:/{print $NF}' | tr '\n' ' ' | sed 's/ $/\n/g')
|
|
|
|
limit=$((100 - inc))
|
|
|
|
maxlimit=$((maxvol - inc))
|
|
|
|
|
|
|
|
updateSinks () {
|
|
|
|
active_sinks=$(pacmd list-sinks |awk '/index:/{print $NF}' | tr '\n' ' ' | sed 's/ $/\n/g')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
volUp () {
|
|
|
|
updateSinks
|
|
|
|
getCurVol
|
|
|
|
|
|
|
|
for sink in ${active_sinks}; do
|
|
|
|
if [ ${capvol} = 'yes' ]; then
|
|
|
|
if [ "${curVol}" -le 100 ] && [ "${curVol}" -ge ${limit} ]; then
|
|
|
|
pactl set-sink-volume "${sink}" 100%
|
|
|
|
elif [ "${curVol}" -lt ${limit} ]; then
|
|
|
|
pactl set-sink-volume "${sink}" +${inc}%
|
|
|
|
fi
|
|
|
|
elif [ "${curVol}" -le ${maxvol} ] && [ "${curVol}" -ge ${maxlimit} ]; then
|
|
|
|
pactl set-sink-volume "${sink}" ${maxvol}%
|
|
|
|
elif [ "${curVol}" -lt ${maxlimit} ]; then
|
|
|
|
pactl set-sink-volume "${sink}" +${inc}%
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
getCurVol
|
|
|
|
|
2019-04-27 02:58:52 +00:00
|
|
|
if [ ${notify} = 'yes' ]; then
|
2017-01-24 01:46:57 +00:00
|
|
|
notify-send "Volume : ${curVol}%" -t ${notiftime}
|
2019-04-27 02:58:52 +00:00
|
|
|
elif [ "$notify" = 'dunst' ]; then
|
|
|
|
dunstify -r "$notifid" -t "$notiftime" "Volume: $curVol%"
|
2017-01-24 01:46:57 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-27 02:58:52 +00:00
|
|
|
if [ ${autosync} = 'yes' ]; then
|
2017-01-24 01:46:57 +00:00
|
|
|
volSync
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
volDown () {
|
|
|
|
updateSinks
|
|
|
|
for sink in ${active_sinks}; do
|
|
|
|
pactl set-sink-volume "${sink}" -${inc}%
|
|
|
|
done
|
|
|
|
getCurVol
|
|
|
|
|
|
|
|
if [ ${notify} = 'yes' ]; then
|
|
|
|
notify-send "Volume : ${curVol}%" -t ${notiftime}
|
2019-04-27 02:58:52 +00:00
|
|
|
elif [ "$notify" = 'dunst' ]; then
|
|
|
|
dunstify -r "$notifid" -t "$notiftime" "Volume: $curVol%"
|
2017-01-24 01:46:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${autosync} = 'yes' ]; then
|
|
|
|
volSync
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
volSync () {
|
|
|
|
updateSinks
|
|
|
|
getCurVol
|
|
|
|
|
|
|
|
for each in ${active_sinks}; do
|
|
|
|
pactl set-sink-volume "${each}" "${curVol}"%
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getCurVol () {
|
|
|
|
curVol=$(pacmd list-sinks |grep -A 15 'index: '"${main_sink}"'' |grep 'volume:' |egrep -v 'base volume:' |awk -F : '{print $3}' |grep -o -P '.{0,3}%'|sed s/.$// | tr -d ' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
volMute () {
|
|
|
|
case "$1" in
|
|
|
|
mute)
|
|
|
|
for sink in ${active_sinks}; do
|
|
|
|
pactl set-sink-mute "${sink}" 1
|
|
|
|
done
|
|
|
|
curVol=0
|
|
|
|
status=1
|
|
|
|
;;
|
|
|
|
unmute)
|
|
|
|
for sink in ${active_sinks}; do
|
|
|
|
pactl set-sink-mute "${sink}" 0
|
|
|
|
done
|
|
|
|
getCurVol
|
|
|
|
status=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ ${notify} = 'yes' ]; then
|
|
|
|
notify-send "$([ "${status}" = 1 ] && echo "Sound muted" || echo "Sound unmuted")" -t ${notiftime}
|
2019-04-27 02:58:52 +00:00
|
|
|
elif [ "$notify" = 'dunst' ]; then
|
|
|
|
dunstify -r "$notifid" -t "$notiftime" "$([ "${status}" = 1 ] && echo "Sound muted" || echo "Sound unmuted")"
|
2017-01-24 01:46:57 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
volMuteStatus () {
|
|
|
|
curStatus=$(pacmd list-sinks |grep -A 15 'index: '"${main_sink}"'' |awk '/muted/{ print $2}')
|
|
|
|
|
|
|
|
if [ "${curStatus}" = 'yes' ]; then
|
|
|
|
volMute unmute
|
|
|
|
else
|
|
|
|
volMute mute
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
volHelp () {
|
|
|
|
echo "Finds the active sink for pulse audio and manages the volume."
|
|
|
|
echo "Options :"
|
|
|
|
echo ""
|
|
|
|
echo " --down"
|
|
|
|
echo " --help"
|
|
|
|
echo " --mute"
|
|
|
|
echo " --sync Sync all sinks volumes"
|
|
|
|
echo " --toggle"
|
|
|
|
echo " --unmute"
|
|
|
|
echo " --up"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
--up)
|
|
|
|
volUp
|
|
|
|
;;
|
|
|
|
--down)
|
|
|
|
volDown
|
|
|
|
;;
|
|
|
|
--toggle)
|
|
|
|
volMuteStatus
|
|
|
|
;;
|
|
|
|
--help)
|
|
|
|
volHelp
|
|
|
|
;;
|
|
|
|
--mute)
|
|
|
|
volMute mute
|
|
|
|
;;
|
|
|
|
--unmute)
|
|
|
|
volMute unmute
|
|
|
|
;;
|
|
|
|
--sync)
|
|
|
|
volSync
|
|
|
|
;;
|
|
|
|
esac
|