jelloir
Status: Interested
Joined: 13 Jul 2009
Posts: 24
Location: Rye, Victoria, Australia
Back to top
Posted: Aug 3, 09, 22:53    OSD (On Screen Display) For Volume in Openbox
I thought I would share a script I have been using on Sid (not Sidux) to control my Volume in Openbox. I found it online and customised it to my liking.

It requires alsa-utils and aosd-cat packages to be installed.

I also recommend you look at the help for aosd_cat for any options you may like to alter.

:: Code ::
#!/bin/bash

#============================================#
#   mixer-osd
#============================================#

case $1 in
   volup) A="VOLUME: $(amixer sset Master 2dB+ | \
   grep "Mono:" | awk '{print $4}' | tr -d '[]')" ;;

   voldown) A="VOLUME: $(amixer sset Master 2dB- | \
   grep "Mono:" | awk '{print $4}' | tr -d '[]')" ;;

   mute)
      case $(amixer set Master toggle | grep "Mono:" \
      | awk '{print $6}' | tr -d '[]') in
         on) A="UNMUTED" ;;
         off) A="MUTED" ;;
      esac ;;
   *) echo "Usage: $0 { volup | voldown | mute }" ;;
esac

pkill aosd_cat &> /dev/null

echo "$A" |  aosd_cat --fore-color=green -p 8 \
--font="Terminus 10" --x-offset=-40 --y-offset=-0 \
--transparency=2 --fade-full=2500 &

# END


Assuming your Distro correctly detects your multimedia key presses for XF86AudioLowerVolume, XF86AudioRaiseVolume and XF86AudioMute then you can add something like this to your rc.xml

:: Code ::
vi ~/.config/openbox/rc.xml


:: Code ::
<keybind key="XF86AudioLowerVolume">
      <action name="Execute">
        <execute>mixer-osd voldown</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <execute>mixer-osd volup</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioMute">
      <action name="Execute">
        <execute>mixer-osd mute</execute>
      </action>
    </keybind>


It should be easy enough to integrate into other WM's and Desktops (using XFCE Keybindings in XFCE for example).

The script could be expanded to include all sorts of options such as Next Audio Track, Play/Pause etc, etc, even brighness level on laptops displays etc.

Thanks
jelloir
Status: Interested
Joined: 13 Jul 2009
Posts: 24
Location: Rye, Victoria, Australia
Back to top
Posted: Oct 4, 09, 2:00    
I have updated this:

When muted the OSD color is red for the mute toggle and volume whilst muted otherwise it is yellow.
Improved the OSD so the transitions are smooth.


Obviously you can change to suit yourself...

:: Code ::
#!/bin/bash
#================================================================================
### mixer-osd
#================================================================================

case $1 in

   volup) A="VOLUME: $(amixer sset Master 2dB+ | grep "Mono:" \
      | awk '{print $4}' | tr -d '[]')" ;;

   voldown) A="VOLUME: $(amixer sset Master 1dB- | grep "Mono:" \
      | awk '{print $4}' | tr -d '[]')" ;;

   mute)
      case $(amixer set Master toggle | grep "Mono:" \
         | awk '{print $6}' | tr -d '[]') in
            on) A="UNMUTED" ;;
            off) A="MUTED" ;;
      esac ;;

   *) echo "Usage: $0 { volup | voldown | mute }" ;;

esac

MUTESTATUS=$(amixer get Master | grep "Mono:" | awk '{print $6}' | tr -d '[]')

if [ $MUTESTATUS == "off" ]; then
   OSDCOLOR=red; else
   OSDCOLOR=yellow
fi

killall aosd_cat &> /dev/null

echo "$A" | aosd_cat -n "Sans 20 bold" -o 3000 -R $OSDCOLOR -f 0

# END
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 2541
Location: East Coast, West Coast? I know it's one of them.
Back to top
Posted: Oct 4, 09, 8:30    
nice stuff, thanks.
Display posts from previous:   

All times are GMT - 8 Hours