Register
It is currently Tue Jul 29, 2014 4:41 am

Mixer OSD


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Wed Sep 02, 2009 10:29 pm   

Joined: Sun Aug 30, 2009 4:11 pm
Posts: 4
This is a simple script that people that use Openbox or similar WMs will find useful, due to the lack of solutions for having an on-screen-display that shows volume informations. There's osdsh, but is not maintained since a long time and has a bug that overloads your cpu when using the volume plugin.

This script is not intended to be run from the command line, although that's obviously possible! It's meant to be used with multimedia keys enabled. For Openbox, given your special keys work (the first howto I found googling is this one), you'll only need to add this stanza to your rc.xml file to, e.g., lower your volume:
Code:
<keybind key="XF86AudioLowerVolume">
  <action name="Execute">
  <command>mixer-osd -d</command>
  </action>
</keybind>

It needs aosd_cat and amixer (alsa-utils in Debian).

Here's the code:
Code:
#!/bin/bash
################################################################################
#
# mixer-osd - Provides an OSD (On Screen Display) for basic mixer operations.
# Based on a script found at http://techpatterns.com/forums/about1354.html,
# provided with no license (original source is unknown), and modified to suit
# my needs.
#
# License:      This program is released under the terms of the GNU General
#               Public License. See http://www.gnu.org/licenses/gpl-3.0.txt for
#               further details.
# Disclaimer:   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
#               WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#               WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#               PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
#               CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#               SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#               LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#               USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
#               AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
#               LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
#               IN ANY WAYOUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
#               OF THE POSSIBILITY OF SUCH DAMAGE.
#
################################################################################

# Name and description
name="mixer-osd"
description="Provides an OSD (On Screen Display) for basic mixer operations."

# Some variables
default_color="green"
acolor=$default_color

# This program depends on aosd_cat and amixer (alsa-utils in Debian)
deps="aosd_cat amixer"

function usage()
{
   show_name=$1
   error=$2

   # Show name and description only if explicitly stated
   if [[ $show_name == 1 ]] ; then
      echo -e " $name - $description\n"
   fi

   # Show an error message, if present
   if [[ $error != '' ]] ; then
      echo -e "\033[1m$error\033[0m\n"
   fi

   cat << EOF
Usage:
   $name -u|-d|-m
   $name -h

Options:
   -u   Volume up
   -d   Volume down
   -m   Mute/Unmute
   
   -h   Shows this help.

EOF
}

# Check for dependencies
for dep in $deps ; do
   if [[ `which $dep` == '' ]] ; then
      echo "Please, install $dep for $name to work!"
      exit 1
   fi
done

# Managing options
while getopts "hudm" option ; do
   case $option in
      h )
         usage 1
         exit 0
         ;;
      u )
         aarg="Volume ↑ $(amixer -c 0 sset Master 2+ unmute | grep 'Front Left:' | awk '{print $5}' | tr -d '[]')"
         acolor="cyan"
         ;;
      d )
         aarg="Volume ↓ $(amixer -c 0 sset Master 2- unmute | grep 'Front Left:' | awk '{print $5}' | tr -d '[]')"
         acolor="yellow"
         ;;
      m )
         case $(amixer -c 0 sset Master toggle | grep 'Front Left:' | awk '{print $7}' | tr -d '[]') in
            on )
               aarg="UNMUTED"
               acolor="green"
               ;;
            off )
               aarg="MUTED"
               acolor="red"
               ;;
         esac
         ;;
      \? )
         echo -e "Please type ${name} -h for help on usage."
         exit 1
         ;;
   esac
done
shift $(($OPTIND - 1))

# This program doesn't accept any other argument than flag-options
if [[ $# -gt 0 ]] ; then
   usage 0 "Invalid argument (\`$1')."
   exit 1
fi

# One have to either mute/unmute or change the volume,
# otherwise program will exit with error code 1
if [[ -z $aarg ]] ; then
   usage 0 "Please, mute/unmute or change the volume!"
   exit 1
fi

# Kills any instance of aosd_cat
pkill aosd_cat >/dev/null 2>&1

# Performs osd-ized volume changes
echo "$aarg" | aosd_cat \
            --fore-color=$acolor \
            --position 4 \
            --font="Sans Bold 32" \
            --y-offset=300 \
            --transparency=2 \
            --fade-full=1500 >/dev/null 2>&1 &

exit $?

Please, let me know if you encounter problems or if something doesn't work. I tested it and it seems to work well though.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP