SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2009-10-09 10:51:55

jelloir
#! CrunchBanger
From: Outside the garden wall
Registered: 2009-08-21
Posts: 212

OSD for openbox using aosd_cat

Hi Crunchbangers,

I thought you may be interested in on OSD volume control script using alsa-utils and aosd_cat (package called aosd-cat).  I haven't actually checked if aosd_cat is in Ubuntu as I use Sid.

When muted the OSD color is red for the mute toggle and volume whilst muted otherwise it is yellow.

Obviously you can change to suit yourself.  It also assumes ~/bin is in your path.

vi ~/bin/mixer-osd
#!/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
chmod +x ~/bin/mixer-osd

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

vi ~/.config/openbox/rc.xml
<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>

Offline

Be excellent to each other!

#2 2009-10-11 14:40:03

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: OSD for openbox using aosd_cat

grrr, i wish you had posted this a few days earlier, just been offline for the past few days, and decided to spend the time writing a volume notification thing in python.
oh well smile


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#3 2009-12-10 02:38:56

slapfish
#! Die Hard
From: Athens, Greece
Registered: 2009-10-22
Posts: 601

Re: OSD for openbox using aosd_cat

AHA!!! I was missing the Acer Windows OSD volume display...until now... big_smile

Many Many thanks!!!!

Hope you don't mind altering your code a little...

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

case $1 in

   volup) $(amixer sset Master 2dB+) ;;

   voldown) $(amixer sset Master 1dB-) ;;

   mute)
      case $(amixer set Master toggle) in
            on) ;;
            off);;
      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=green
fi

killall aosd_cat &> /dev/null

volI=$(amixer get Master | grep "Mono:" | awk '{print $3}')

   if [ $volI == "31" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "30" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "29" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "28" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "27" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "26" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "25" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "24" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "23" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "22" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "21" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "20" ]; then
   OSDI="IIIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "19" ]; then
   OSDI="IIIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "18" ]; then
   OSDI="IIIIIIIIIIIIIIIIII"; fi
   if [ $volI == "17" ]; then
   OSDI="IIIIIIIIIIIIIIIII"; fi
   if [ $volI == "16" ]; then
   OSDI="IIIIIIIIIIIIIIII"; fi
   if [ $volI == "15" ]; then
   OSDI="IIIIIIIIIIIIIII"; fi
   if [ $volI == "14" ]; then
   OSDI="IIIIIIIIIIIIII"; fi
   if [ $volI == "13" ]; then
   OSDI="IIIIIIIIIIIII"; fi
   if [ $volI == "12" ]; then
   OSDI="IIIIIIIIIIII"; fi
   if [ $volI == "11" ]; then
   OSDI="IIIIIIIIIII"; fi
   if [ $volI == "10" ]; then
   OSDI="IIIIIIIIII"; fi
   if [ $volI == "9" ]; then
   OSDI="IIIIIIIII"; fi
   if [ $volI == "8" ]; then
   OSDI="IIIIIIII"; fi
   if [ $volI == "7" ]; then
   OSDI="IIIIIII"; fi
   if [ $volI == "6" ]; then
   OSDI="IIIIII"; fi
   if [ $volI == "5" ]; then
   OSDI="IIIII"; fi
   if [ $volI == "4" ]; then
   OSDI="IIII"; fi
   if [ $volI == "3" ]; then
   OSDI="III"; fi
   if [ $volI == "2" ]; then
   OSDI="II"; fi
   if [ $volI == "1" ]; then
   OSDI="I"; fi
   if [ $volI == "0" ]; then
   OSDI=""; fi
   
echo "$OSDI" | aosd_cat -n "Arial Black 104" -u 1000 -o 200 -R $OSDCOLOR -S none -f 0 -y -10


# END

I don't really know anything about programming so I tried to understand what your code does and I alter it as I could... if you think that there is a better way to do what I have done please do correct it...

the output is like that:

Vol maxed:      th_ce9f4464.png            Vol down and muted:      th_fc62581b.png

Offline

#4 2009-12-12 04:02:02

Thaery
#! Member
Registered: 2009-10-19
Posts: 79

Re: OSD for openbox using aosd_cat

Awesome! I can think of some uses for the keyboard jockey big_smile

Offline

#5 2010-02-15 21:26:20

elumbella
Member
Registered: 2010-02-15
Posts: 46

Re: OSD for openbox using aosd_cat

Hi there!

Thanks a lot for this script, it does fine controling my volume. But what it doesn't is: Muting doesn't work, as same as printing the current volume resp. the bars. What i found out is, that "amixer get PCM,0" doesn't have output for "Mono:"(PCM,0 is my audio device, didn't work with Master) :

Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 138 [54%] [-23.40dB]
  Front Right: Playback 138 [54%] [-23.40dB]

Any ideas how i can grep the volume?

Offline

#6 2010-02-16 20:58:30

Undarl
New Member
From: Central Maine, USA
Registered: 2010-02-16
Posts: 9

Re: OSD for openbox using aosd_cat

Heya, jelloir and slapfish!

Excellent work on this. Haven't had a working OSD volume display in a while, and they work so well when mapped to my multimedia keys.

I built a slightly different version of slapfish's script to allow me to fiddle with volume granularity and font size a little more easily, then decided I might as well make it slightly more universal and repost it.

#!/bin/bash
#================================================================================
### mixer-osd
## Modified from the work of jelloir and slapfish on the CrunchBang
## Linux Forums.
#================================================================================

# Some user-defined values
MIXERNAME="Master" # The name of the amixer master device
GRANULARITY=32 # The approximate number of possible volume positions allowed
FONTSIZE=116 # The size of font used by the OSD display
# Fontsize often needs to change when granularity changes

# Pull the numerical limit from the Mixer
LIMIT=$(amixer get $MIXERNAME | grep "Limits" | awk '{print $5}')

# Set volume increment based on granularity
let VOLINC=LIMIT/GRANULARITY
let volmod=LIMIT%GRANULARITY
let threshold=GRANULARITY/2
if [ $volmod -gt $threshold ]; then
   let VOLINC=VOLINC+1
fi

# Command line handler
case $1 in

   volup) $(amixer set $MIXERNAME $VOLINC+) ;;

   voldown) $(amixer set $MIXERNAME $VOLINC-) ;;

   mute) $(amixer set $MIXERNAME toggle) ;;

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

esac

# Detect mute status and set OSD color
MUTESTATUS=$(amixer get $MIXERNAME | grep "Mono:" | awk '{print $6}' | tr -d '[]')

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


# Create the "I" bar based on mixer setting and granularity
volset=$(amixer get $MIXERNAME | grep "Mono:" | awk '{print $3}')

let volcounter=volset/$VOLINC
if [ $volcounter -gt $GRANULARITY ]; then
   volcounter=$GRANULARITY
fi

OSDI=""

while [ $volcounter -gt 0 ]
do
   OSDI=`echo $OSDI"I"`
   let volcounter=volcounter-1
done    

# Clean up any running aosd_cat processes
killall aosd_cat &> /dev/null

# Display the "I" bar
echo "$OSDI" | aosd_cat -n "Arial Black $FONTSIZE" -u 1000 -o 200 -R $OSDCOLOR -S none -f 0 -y -10


# END

Comments, fixes, and further rewrites welcome. smile

Offline

#7 2010-02-16 21:00:37

Undarl
New Member
From: Central Maine, USA
Registered: 2010-02-16
Posts: 9

Re: OSD for openbox using aosd_cat

elumbella wrote:

Thanks a lot for this script, it does fine controling my volume. But what it doesn't is: Muting doesn't work, as same as printing the current volume resp. the bars. What i found out is, that "amixer get PCM,0" doesn't have output for "Mono:"(PCM,0 is my audio device, didn't work with Master)

Any ideas how i can grep the volume?

It doesn't look like that PCM device supports the standard Alsa mute toggle. Is there perhaps another usable device? Could you post the output of the 'amixer' command?

Offline

#8 2010-02-23 19:39:38

elumbella
Member
Registered: 2010-02-15
Posts: 46

Re: OSD for openbox using aosd_cat

Hey Undarl!
The output of "amixer" is the following. I'm using an Asus Eee-PC, if that helps.

Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 216 [85%] [-7.80dB]
  Front Right: Playback 216 [85%] [-7.80dB]
Simple mixer control 'LineOut',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 64
  Mono:
  Front Left: Playback 64 [100%] [1.00dB] [on]
  Front Right: Playback 64 [100%] [1.00dB] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 46
  Front Left: Capture 21 [46%] [4.00dB] [on]
  Front Right: Capture 21 [46%] [4.00dB] [on]
Simple mixer control 'iSpeaker',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [on]
  Front Right: Playback [on]

Offline

#9 2010-02-23 20:50:26

Zwopper
The GIMP Pimp
From: Deep in The Swedish Woods
Registered: 2008-11-28
Posts: 580
Website

Re: OSD for openbox using aosd_cat

Would it be possible to just get an "X" or somehow get it to actually spell out "muted", or something instead of altering the color?
Pardon my extreme lack of understanding of scripting, but I'll get into it more over time, I hope. big_smile


My artwork at deviantART   |    My Tweet   | My upcoming web page
Crea diem!
Lenovo ThinkPad E320 | 8GB | 512GB Samsung 840 PRO SSD | Xubuntu 13.04 & #! Waldorf

Offline

#10 2010-02-24 01:27:24

Undarl
New Member
From: Central Maine, USA
Registered: 2010-02-16
Posts: 9

Re: OSD for openbox using aosd_cat

elumbella wrote:
Simple mixer control 'LineOut',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 64
  Mono:
  Front Left: Playback 64 [100%] [1.00dB] [on]
  Front Right: Playback 64 [100%] [1.00dB] [on]

Simple mixer control 'iSpeaker',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [on]
  Front Right: Playback [on]

Heya, elum.

The above two look like your best bets. I haven't worked with an Eee previously, but I'd guess that LineOut is your headphone/external speaker jack and iSpeaker is your internal speakers. They both have [on] indicators on their Playback and "pswitch" in their Capabilities, which I believe should make them responsive to mute and toggle commands.

Try these...

amixer set LineOut toggle
amixer set iSpeaker toggle

...and let us know what happens? They can both be toggled at once by the script if that's what it takes.

Offline

#11 2010-02-24 02:01:32

Undarl
New Member
From: Central Maine, USA
Registered: 2010-02-16
Posts: 9

Re: OSD for openbox using aosd_cat

Zwopper wrote:

Would it be possible to just get an "X" or somehow get it to actually spell out "muted", or something instead of altering the color?

How's this? By default it displays the green "I" bar during volume changes or unmute, but changes to a red "MUTED" when mute goes on. Text colors and mute text have been added to the top variable section as well.

#!/bin/bash
#================================================================================
### mixer-osd
## Modified from the work of jelloir and slapfish on the CrunchBang
## Linux Forums.
## **Alternate version for Zwopper. :)
#================================================================================

# Some user-defined values
MIXERNAME="Master" # The name of the amixer master device
GRANULARITY=32 # The approximate number of possible volume positions allowed
FONTSIZE=116 # The size of font used by the OSD display
# Fontsize often needs to change when granularity changes
VOLCOLOR=green # Color for volume bar
MUTECOLOR=red # Color for mute notification
MUTETEXT="MUTED" # The mute text to show

# Pull the numerical limit from the Mixer
LIMIT=$(amixer get $MIXERNAME | grep "Limits" | awk '{print $5}')

# Set volume increment based on granularity
let VOLINC=LIMIT/GRANULARITY
let volmod=LIMIT%GRANULARITY
let threshold=GRANULARITY/2
if [ $volmod -gt $threshold ]; then
   let VOLINC=VOLINC+1
fi

# Command line handler
case $1 in

   volup) $(amixer set $MIXERNAME $VOLINC+ > /dev/null) ;;

   voldown) $(amixer set $MIXERNAME $VOLINC- > /dev/null) ;;

   mute) $(amixer set $MIXERNAME toggle > /dev/null) ;;

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

esac

# Detect mute status and determine OSD output
MUTESTATUS=$(amixer get $MIXERNAME | grep "Mono:" | awk '{print $6}' | tr -d '[]')

if [ $MUTESTATUS == "off" ]; then
   OSDCOLOR="$MUTECOLOR"
   OSDI="$MUTETEXT"
else
   OSDCOLOR="$VOLCOLOR"

   # Create the "I" bar based on mixer setting and granularity
   volset=$(amixer get $MIXERNAME | grep "Mono:" | awk '{print $3}')

   let volcounter=volset/$VOLINC
   if [ $volcounter -gt $GRANULARITY ]; then
      volcounter=$GRANULARITY
   fi

   OSDI=""

   while [ $volcounter -gt 0 ]
   do
      OSDI=`echo $OSDI"I"`
      let volcounter=volcounter-1
   done    
fi

# Clean up any running aosd_cat processes
killall aosd_cat &> /dev/null

# Display the overlay
echo "$OSDI" | aosd_cat -n "Arial Black $FONTSIZE" -u 1000 -o 200 -R $OSDCOLOR -S none -f 0 -y -10


# END

Offline

#12 2010-02-24 06:19:21

mahatman2
#! Die Hard
From: Chattanooga TN
Registered: 2009-09-13
Posts: 550

Re: OSD for openbox using aosd_cat

This script works well, and looks cool except for one tiny thing: when I press the volume button rapidly, or hold it down, the OSD blinks on and off. It does this with all versions of the script, the original and the modified for bars and the other modifieds. It's not that big of a deal, the program does its job, but it is a little annoying. It would be cool to see this fixed....

Anyway thanks for a cool program though! If it helps I have it in ~/bin, would that affect the speed at all?


Punch all your friends.

Offline

#13 2010-02-24 06:59:23

Undarl
New Member
From: Central Maine, USA
Registered: 2010-02-16
Posts: 9

Re: OSD for openbox using aosd_cat

mahatman2 wrote:

This script works well, and looks cool except for one tiny thing: when I press the volume button rapidly, or hold it down, the OSD blinks on and off.

Heya, mahatman2.

I'm assuming you that you mean that the "I" display seems to flicker rapidly when you hit volume up or down while the volume display is still onscreen.

If so, this is an artifact caused by a combination of two things: the fact that the script kills any other aosd_cat processes running before it starts a new one, and the fact that the script gives the displayed text a dwell time of 1 second (1000 milliseconds, the -u option) and a fade time of 2/10 of a second (200 millseconds, the -o option).

The flicker goes away if you remove or comment out the killall line and change the aosd_cat line to have a very short dwell time and no fade time (say, -u 200 -o 0). However, all displayed text would only be onscreen for 2/10 of a second after you press the button.

If the killall line is removed without changing the aosd dwell/fade times, the flicker stops but the bars overwrite each other until they fade out. That looks fine when raising volume, but not so good when lowering it. If the dwell/fade times are changed without removing the killall the flicker remains, because the display is actually being killed momentarily before a new one is created.

You can play with dwell/fade times to your own taste, but the end of the script with the 200/0 times described above looks like this:

# Clean up any running aosd_cat processes
#killall aosd_cat &> /dev/null

# Display the overlay
echo "$OSDI" | aosd_cat -n "Arial Black $FONTSIZE" -u 200 -o 0 -R $OSDCOLOR -S none -f 0 -y -10

# END

Offline

#14 2010-02-24 14:40:41

mahatman2
#! Die Hard
From: Chattanooga TN
Registered: 2009-09-13
Posts: 550

Re: OSD for openbox using aosd_cat

Thanks for the thorough explanation, undarl. If you don't mind a suggestion after knowing what I now know, I think it would be cool to have something like tv's do, that is, a two-color display where there would always be the same number of bars but the inactive ones would be grey or some other color. I mean like this, for say 40% volume:

IIIIiiiiii

where I is green and i is grey. I don't know how hard this would be to implement, so I'm sorry if it isn't possible. I just thought it might be cool.... smile I was going to try to learn bash, so maybe I'll try my hand at it!


Punch all your friends.

Offline

#15 2010-02-24 18:43:14

Undarl
New Member
From: Central Maine, USA
Registered: 2010-02-16
Posts: 9

Re: OSD for openbox using aosd_cat

mahatman2 wrote:

Thanks for the thorough explanation, undarl.

Welcome. smile

If you don't mind a suggestion after knowing what I now know, I think it would be cool to have something like tv's do, that is, a two-color display where there would always be the same number of bars but the inactive ones would be grey or some other color.

Hmmm.  I suspect -- given what I currently know about aosd_cat -- that the "easy" way to do that would be to put up two bars right over top of one another in very quick succession, first a max-size neutral one and then a correctly-sized colored one. My brief fiddling with the code tells me that's slightly more involved than it sounds based on the current script, but I'll maybe take a look at it more later. The only other option that comes to mind is to create two non-overlapping osd displays, but that gets into geometry options that will not play nice with font changes and would generally make the script much less easily configurable.

Offline

#16 2010-02-24 18:50:53

Zwopper
The GIMP Pimp
From: Deep in The Swedish Woods
Registered: 2008-11-28
Posts: 580
Website

Re: OSD for openbox using aosd_cat

Undarl wrote:
Zwopper wrote:

Would it be possible to just get an "X" or somehow get it to actually spell out "muted", or something instead of altering the color?

How's this? By default it displays the green "I" bar during volume changes or unmute, but changes to a red "MUTED" when mute goes on. Text colors and mute text have been added to the top variable section as well.

#!/bin/bash
#================================================================================
### mixer-osd
## Modified from the work of jelloir and slapfish on the CrunchBang
## Linux Forums.
## **Alternate version for Zwopper. :)
#================================================================================

# Some user-defined values
MIXERNAME="Master" # The name of the amixer master device
GRANULARITY=32 # The approximate number of possible volume positions allowed
FONTSIZE=116 # The size of font used by the OSD display
# Fontsize often needs to change when granularity changes
VOLCOLOR=green # Color for volume bar
MUTECOLOR=red # Color for mute notification
MUTETEXT="MUTED" # The mute text to show

# Pull the numerical limit from the Mixer
LIMIT=$(amixer get $MIXERNAME | grep "Limits" | awk '{print $5}')

# Set volume increment based on granularity
let VOLINC=LIMIT/GRANULARITY
let volmod=LIMIT%GRANULARITY
let threshold=GRANULARITY/2
if [ $volmod -gt $threshold ]; then
   let VOLINC=VOLINC+1
fi

# Command line handler
case $1 in

   volup) $(amixer set $MIXERNAME $VOLINC+ > /dev/null) ;;

   voldown) $(amixer set $MIXERNAME $VOLINC- > /dev/null) ;;

   mute) $(amixer set $MIXERNAME toggle > /dev/null) ;;

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

esac

# Detect mute status and determine OSD output
MUTESTATUS=$(amixer get $MIXERNAME | grep "Mono:" | awk '{print $6}' | tr -d '[]')

if [ $MUTESTATUS == "off" ]; then
   OSDCOLOR="$MUTECOLOR"
   OSDI="$MUTETEXT"
else
   OSDCOLOR="$VOLCOLOR"

   # Create the "I" bar based on mixer setting and granularity
   volset=$(amixer get $MIXERNAME | grep "Mono:" | awk '{print $3}')

   let volcounter=volset/$VOLINC
   if [ $volcounter -gt $GRANULARITY ]; then
      volcounter=$GRANULARITY
   fi

   OSDI=""

   while [ $volcounter -gt 0 ]
   do
      OSDI=`echo $OSDI"I"`
      let volcounter=volcounter-1
   done    
fi

# Clean up any running aosd_cat processes
killall aosd_cat &> /dev/null

# Display the overlay
echo "$OSDI" | aosd_cat -n "Arial Black $FONTSIZE" -u 1000 -o 200 -R $OSDCOLOR -S none -f 0 -y -10


# END

THANKS! big_smile
Will try it out tonight!


My artwork at deviantART   |    My Tweet   | My upcoming web page
Crea diem!
Lenovo ThinkPad E320 | 8GB | 512GB Samsung 840 PRO SSD | Xubuntu 13.04 & #! Waldorf

Offline

#17 2010-02-24 19:15:31

elumbella
Member
Registered: 2010-02-15
Posts: 46

Re: OSD for openbox using aosd_cat

Thanks a lot guys, finally i got it working. My current script is this:

#!/bin/bash
#================================================================================
### mixer-osd
## Modified from the work of jelloir and slapfish on the CrunchBang
## Linux Forums.
#================================================================================

# Some user-defined values
MIXERNAME="PCM" # The name of the amixer master device
GRANULARITY=32 # The approximate number of possible volume positions allowed
FONTSIZE=80 # The size of font used by the OSD display
# Fontsize often needs to change when granularity changes

# Pull the numerical limit from the Mixer
LIMIT=$(amixer get $MIXERNAME | grep "Limits" | awk '{print $5}')

# Set volume increment based on granularity
let VOLINC=LIMIT/GRANULARITY
let volmod=LIMIT%GRANULARITY
let threshold=GRANULARITY/2
if [ $volmod -gt $threshold ]; then
   let VOLINC=VOLINC+1
fi

# Command line handler
case $1 in

   volup) (amixer set $MIXERNAME $VOLINC+) ;;

   voldown) (amixer set $MIXERNAME $VOLINC-) ;;

   mute) (amixer set iSpeaker toggle && amixer set LineOut toggle) ;;

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

esac

# Detect mute status and set OSD color
MUTESTATUS=$(amixer get iSpeaker | grep "Left:" | awk '{print $4}' | tr -d '[]')

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


# Create the "I" bar based on mixer setting and granularity
volset=$(amixer get $MIXERNAME | grep "Left:" | awk '{print $4}')

let volcounter=volset/$VOLINC
if [ $volcounter -gt $GRANULARITY ]; then
   volcounter=$GRANULARITY
fi

OSDI=""

while [ $volcounter -gt 0 ]
do
   OSDI=`echo $OSDI"I"`
   let volcounter=volcounter-1
done    

# Clean up any running aosd_cat processes
killall aosd_cat &> /dev/null

# Display the "I" bar
echo "$OSDI" | aosd_cat -n "Arial Black $FONTSIZE" -u 100 -o 35 -R $OSDCOLOR -S none -f 0 -y -10


# END

Offline

#18 2010-04-06 17:01:38

slapfish
#! Die Hard
From: Athens, Greece
Registered: 2009-10-22
Posts: 601

Re: OSD for openbox using aosd_cat

On statler I couldn't find aosd_cat and I was "forced" to install xosd-bin only to find it handles better transparency and screen placement. you might have noticed that with aosd_cat we were only getting fake transparency (screenshot of background). The only problem is with the font settings... if you replace aosd_cat with osd_cat on the code and also use a similar output to this:

echo "$OSD" | osd_cat --pos=bottom --color=$OSDCOLOR --offset=-110 --delay=2 --age=2 --align=center --font="-*-courier-bold-r-*-*-44-*-*-*-*-*-*-*"

you're good to go...


EDIT: xfontsel can give you the format of the font you want to use, although for a reason that I don't know, not all fonts are working. Also I just noticed that helvetica is fixed-width and can be used with my setup which for output it has something like that:

vol maxed: IIIIIIIIII
vol halved: IIIII:::::
vol muted: ::::::::::

Last edited by slapfish (2010-04-06 23:12:00)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo