You are not logged in.

#1 2007-02-26 15:54:59

kamagurka
Member
From: Munich, Germany
Registered: 2006-02-20
Posts: 150
Website

Simple script to adjust Vol: Problem with xosd output

I'm trying to write a simple script to adjust the Master volume and outputting it in a fancy bar with ods_cat (so I can then map it to a button to a remote). It's actually two scripts, one for Volume up, and one for Volume Down, but they are identical except for one character.
Here it is:

cat /usr/local/bin/volup
#!/bin/sh
amixer set Master 3%+ | grep Left: | awk '{ gsub(/\[/, " "); gsub(/%\]/, " "); print $5 }' | xargs osd_cat -b percentage -p middle -A center -P&

It works pretty well, my problem is that if I execute the command another time within the five seconds osd_cat is still displaying, the two outputs overlay, and that pretty much renders the output useless. The only solutions I can think of are either having the script grep ps for osd_cat, and if there are any instances, killing them, or having every iteration of the command write the PID of osd_cat into a temporary file and having the next instance read that and kill the PID. Both solutions seem bulky to me and also transcend what I can do in bash, since I actually have no idea how if statements work in bash. I wish I knew how to do what I wrote above in Python, since I know a little more about that.
Anyway, can anyone think of a simpler way to do what I need, or at least a short and sweet way to translate the "solutions" I already thought of into actual code?
Also, if you can think of stuff to optimize my already existing code, go ahead. Personally, I'm proud that my awk command works as intended, but I'm sure a real bash-wizard would do this different.


I always roll 20s on my disbelieve checks.
You better believe it.

Offline

#2 2007-02-26 21:06:42

gradgrind
Member
From: Germany
Registered: 2005-10-06
Posts: 921

Re: Simple script to adjust Vol: Problem with xosd output

If you are happier with python why not try pyosd (http://repose.cx/pyosd/ - PKGBUILD in AUR)?
It seems to work pretty well and updating displays is no problem.

Offline

#3 2007-02-28 06:04:27

kamagurka
Member
From: Munich, Germany
Registered: 2006-02-20
Posts: 150
Website

Re: Simple script to adjust Vol: Problem with xosd output

Well, my point is that I am not savvy enough to replicate the pipe to awk to xargs in python. But maybe I'll just keep trying, I need to learn more python anyways.


I always roll 20s on my disbelieve checks.
You better believe it.

Offline

#4 2007-02-28 20:25:01

gradgrind
Member
From: Germany
Registered: 2005-10-06
Posts: 921

Re: Simple script to adjust Vol: Problem with xosd output

See the 'subprocess' module for pipes, etc. But why not do it all in python, then you don't need grep, awk, xargs? It may take a few more lines, but it might be more readable (or am I being unfair?).

Offline

#5 2007-03-01 15:06:53

kamagurka
Member
From: Munich, Germany
Registered: 2006-02-20
Posts: 150
Website

Re: Simple script to adjust Vol: Problem with xosd output

I don't think you're being unfair; I'm sure it will look better and be easier in python, however, I will need to acquire more python skills to get it done. But having a concrete challenge is exactly what I need to get me started with exactly that.


I always roll 20s on my disbelieve checks.
You better believe it.

Offline

#6 2007-03-16 14:22:49

SiD
Member
From: Germany
Registered: 2006-09-21
Posts: 729

Re: Simple script to adjust Vol: Problem with xosd output

I've made a bash-script to increase / decrease PCM volume and show a %bar with osd_cat.

There are no problems reading the output of osd_cat if the script is executed within the delay time of one second.
But there is a delay in the output if I press the Vol-keys more than once in a short time (<1sec.). I think the --delay option of osd_cat is the reason, but "1" is the minimum for that option. I tried to set it to values between 1 and 0 but that does not work...

I tried to kill osd_cat just before it's executed in the script using "killall osd_cat", but if I do so the output flickers if the script is executed several times in a short time.
So, if anybody has a solution....

this is the script

#!/bin/bash

case $1 in
+)
        amixer -c 0 set PCM 2dB+
        ;;
-)
        amixer -c 0 set PCM 2dB-
        ;;
*)
        exit 
        ;;
esac

VOLUME=`amixer get PCM | sed -ne '/Front Left/s/.*\[\(.*\)%\].*/\1/p'`

osd_cat --font -*-terminus-*-*-*-*-*-*-*-*-*-*-*-* --colour=Green --shadow 1 \
--pos bottom --align center --offset 80 --delay=1 -b percentage -P $VOLUME -T PCM\ Volume

Last edited by SiD (2007-03-16 14:34:40)

Offline

#7 2007-03-25 19:29:00

kamagurka
Member
From: Munich, Germany
Registered: 2006-02-20
Posts: 150
Website

Re: Simple script to adjust Vol: Problem with xosd output

Well, you're right, the delay option is the culprit.
My problem is that I want the bar to show up for about 3 seconds, but I want it to update if I issue the command again. However, it seems to be a limitation of osd_cat that it will overlay the output of two bars if the command is issued within the delay period. I'll post here again should I ever manage to solve this in python, maybe the pyosd implementation can manage that.


I always roll 20s on my disbelieve checks.
You better believe it.

Offline

Board footer

Powered by FluxBB