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).
Here's the modified script. Thoughts?
- Code: Select all
#!/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).