Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
#!/bin/bash
# /usr/local/bin/pavolcontrol
#
# Copyright (C) 2012 Maze <maze@pkbd.org>
#
# pavolcontrol is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pavolcontrol is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pavolcontrol. If not, see <http://www.gnu.org/licenses/>.
INCREMENT=5
function get_mute_status
{
ISMUTE=0
if ( pactl list sinks | grep "Mute: yes" ) ; then
ISMUTE=1
fi
}
function toggle_mute
{
get_mute_status
declare -i NEWMUTE=1-$ISMUTE
pactl set-sink-mute 0 $NEWMUTE
}
function get_cur_vol
{
CURVOL=$( pactl list sinks | awk '/Volume: 0:/ {print substr($3, 1, index($3, "%") - 1)}' )
}
case "$1" in
increase) get_cur_vol
declare -i NEWVOL=$CURVOL+$INCREMENT
pactl set-sink-volume 0 ${NEWVOL}"%"
;;
decrease) get_cur_vol
declare -i NEWVOL=$CURVOL-$INCREMENT
pactl set-sink-volume 0 ${NEWVOL}"%"
;;
toggle) toggle_mute
;;
*) echo "Usage: /usr/local/bin/pavolctrl {increase|decrease|toggle}"
exit 2
;;
esac
exit 0
lancelot wrote:If you find yourself trying this script, please give me feedback, I'd like to know if it works for everyone.
Thanks man, this is awesome!. Unfortunately I found a problem with it. In my laptop, I find myself constantly using the HDMI audio output to watch videos on a TV. Normally I use pavucontrol to switch to the HDMI output. However, everytime this changes, the sink number changes, even when I switch back to the laptop speakers (not sure why this is so...some internal pulseaudio stuff I guess...I wonder if this is how it's supposed to work) rendering your awesome script unusable. I think I feel confident enough to modify it to account for this issue (I'm thinking creating a get_sink_num function, similar to your get_cur_vol or get_mute_status). I will post it when I've tested it... but if you beat me to it, let me know!
I got it working! I'm so happy!
I used a similar trick as the get_cur_vol function you used. However, I can see limitations in this script. For example, if there are several sinks, it will only choose the first one (which I suppose is the default one...but I'm not sure).
#!/bin/bash
# /usr/local/bin/pavolctl
#
# Copyright (C) 2012 Maze <maze@pkbd.org>
#
# pavolctl is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pavolctl is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pavolctl. If not, see <http://www.gnu.org/licenses/>.
INCREMENT=5
function get_sink_num
{
SINK_NUM=$( pactl list short sinks | awk '{print $1}')
}
function get_mute_status
{
ISMUTE=0
if ( pactl list sinks | grep "Mute: yes" ) ; then
ISMUTE=1
fi
}
function toggle_mute
{
get_mute_status
get_sink_num
declare -i NEWMUTE=1-$ISMUTE
pactl set-sink-mute $SINK_NUM $NEWMUTE
}
function get_cur_vol
{
CURVOL=$( pactl list sinks | awk '/Volume: 0:/ {print substr($3, 1, index($3, "%") - 1)}' )
}
case "$1" in
increase)
get_cur_vol
get_sink_num
if [ $CURVOL -lt 100 ]; then
declare -i NEWVOL=$CURVOL+$INCREMENT
pactl set-sink-volume $SINK_NUM ${NEWVOL}"%"
fi
;;
decrease)
get_cur_vol
get_sink_num
declare -i NEWVOL=$CURVOL-$INCREMENT
pactl set-sink-volume $SINK_NUM ${NEWVOL}"%"
;;
toggle)
toggle_mute
;;
*)
echo "Usage: /usr/local/bin/pavolctl {increase|decrease|toggle}"
exit 2
;;
esac
exit 0
EDIT: I modified the script yet once more to put a constraint on the volume so that it can't be increased over 100% (pactl allows the volume to go up to 150%, which makes my speakers crackle).
Please also note, that in localised versions, "Mute: yes" might be replaced by "Stumm: yes" or something else. It is really disturbing, that we have to parse ununified output. Is there not anything like get-sink-mute or something? Maybe some other pulse audio utility that can do this?