Pulse audio volume control with extra amplification

It's amazing how good are yad windows being handled is window manager in 17.10
I made this bash script for pulse volume control for xfce desktop but undecorated windows are hard to position. On openbox it's even more comlicated because it's not focusing that kind of windows and some extra steps with devilspie are needed. On mate-desktop it works preety well so far.
The slider in the tray goes only to 100%., this he pseudo-tray application can go over the top up to 150%. You can change that in the script but be carefull not to damage the speakers by oversimplifying.
Required packages: yad, xdotool, notify-send, pulseaudio-utils

[code]#!/bin/bash
#######################################################

Description:

bash script to set the pulseaudio volume

via yad UI - author Misko_2083

#######################################################

ERR(){ echo "ERROR: $1" 1>&2; }

declare -i DEPCOUNT=0
for DEP in /usr/bin/{xdotool,yad,pactl,pacmd,notify-send}; {
[ -x "$DEP" ] || {
ERR "$LINENO Dependency '$DEP' not met."
DEPCOUNT+=1
}
}
[ $DEPCOUNT -eq 0 ] || exit 1

export YAD_PULSE=$(mktemp -u --tmpdir YAD_PULSE.XXXXXXXX)
mkfifo "$YAD_PULSE"
trap "rm -f $YAD_PULSE" EXIT

yad_pulse_audio(){

set window class

YAD_CLASS="YAD_PULSE_AUDIO"

Unmap the window if the script is relaunched

pids="$(xdotool search --class "$YAD_CLASS")"
wpid="$(xdotool getwindowfocus)"

for pid in $pids; do
# Compares window class pid with the pid of a window in focus
if [[ "$pid" == "$wpid" ]]; then
xdotool windowunmap $pid
exit 1
fi
done

SINK="$(pacmd list-sinks | awk '/* index: [0-9]+/{ print $3 }')"

current volume snippet taken

from pulseaudio-ctl https://github.com/graysky2/pulseaudio-ctl

by graysky [email protected], licensed under MIT

CURVOL="$(pacmd list-sinks | grep -A 15 '* index' | awk '/volume: /{ print $3 }' | grep -m 1 % | sed 's/[%|,]//g')"
[ -n "$CURVOL" ] || CURVOL="$(pacmd list-sinks | grep -A 15 '* index' | awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g')"
[ -n "$CURVOL" ] || CURVOL=100

#printf "Current volume: %3d%%\n" "$CURVOL"
#printf "\rVolume: %3d%%" "$CURVOL"
#pactl set-sink-volume "$SINK" "$CURVOL%"

yad --scale
--print-partial
--text=" Volume Control "
--min-value=0 --max-value=150
--image="audio-speakers"
--borders="12"
--no-buttons
--undecorated
--close-on-unfocus
--on-top
--skip-taskbar
--mouse
--sticky
--class="$YAD_CLASS"
--value="$CURVOL" 2> /dev/null |
while read VOL; do
set_notification_icon $(printf "%3d" "$VOL")
pactl set-sink-volume "$SINK" "$VOL%"
done
}
export -f yad_pulse_audio

function set_notification_icon
{
LANG=C.UTF-8

if [[ "$1" -ge "68" ]]; then
echo "icon:audio-volume-high-panel"

elif [[ "$1" -ge "34" && "$1" -lt "68" ]]; then
echo "icon:audio-volume-medium-panel"

elif [[ "$1" -ge "1" && "$1" -lt "34" ]]; then
echo "icon:audio-volume-low-panel"

elif [[ "$1" -lt "1" ]]; then
echo "icon:audio-volume-low-zero-panel"
fi

echo "tooltip:Volume $1 %"
echo "menu:Sound Settings!mate-volume-control!sound-preferences|About!sh -c 'notify-send -i notification-audio-volume-high -t 8000 "Pulseaudio Volume Control" "by Misko_2083"'!gtk-about||Quit!quit!gtk-quit"
}
export -f set_notification_icon

exec 3<> $YAD_PULSE

yad --notification --command="bash -c 'yad_pulse_audio >$YAD_PULSE'"
--listen <&3 & notifpid=$!

until xdotool getwindowname $(xdotool search --pid "$notifpid" | tail -1) &>/dev/null; do
# sleep until the window opens
sleep 0.5
done

SINK="$(pacmd list-sinks | awk '/* index: [0-9]+/{ print $3 }')"

current volume snippet taken

from pulseaudio-ctl https://github.com/graysky2/pulseaudio-ctl

by graysky [email protected], licensed under MIT

CURVOL="$(pacmd list-sinks | grep -A 15 '* index' | awk '/volume: /{ print $3 }' | grep -m 1 % | sed 's/[%|,]//g')"
[ -n "$CURVOL" ] || CURVOL="$(pacmd list-sinks | grep -A 15 '* index' | awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g')"
[ -n "$CURVOL" ] || CURVOL=100

set_notification_icon $(printf "%3d" "$CURVOL") >&3

Waits for notification to exit

wait $notifpid

exec 3>&-

exit 0[/code]
*Note - The script uses the icons from default icon theme Ambiant-MATE

1 Like