SEARCH

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

You are not logged in.

#1 2011-03-30 19:19:25

bozhkov
#! Junkie
Registered: 2009-12-29
Posts: 464

Notify-osd in openbox

Hello, I have set my fn volume keys via the rc.xml file, but I was wondering if I can add notifications for that via notify-osd. Here is the relevant part of my rc.xml:

<keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <command>amixer sset PCM,0 5+</command>
      </action>
    </keybind>
    <keybind key="XF86AudioLowerVolume">
      <action name="Execute">
        <command>amixer sset PCM,0 5-</command>
      </action>
    </keybind>
    <keybind key="XF86AudioMute">
      <action name="Execute">
        <command>amixer sset Master,0 toggle</command>
      </action>
    </keybind>

PS: I am not sure if this is the right place for this topic, please feel free to move it, if necessary. smile

Offline

Be excellent to each other!

#2 2011-03-30 19:34:30

aiBo
#! CrunchBanger
Registered: 2010-11-08
Posts: 243

Re: Notify-osd in openbox

Offline

#3 2011-03-30 21:25:24

bozhkov
#! Junkie
Registered: 2009-12-29
Posts: 464

Re: Notify-osd in openbox

This is way over my head, I have to admit. :S I tried to make sense of the scripts there, compared them to cb-fortune to find out how it was using notify-osd, but I have way too little knowledge in both bash and python.

Offline

#4 2011-03-30 22:13:21

aiBo
#! CrunchBanger
Registered: 2010-11-08
Posts: 243

Re: Notify-osd in openbox

Don't bother with python syntax. It's only bash.

They just put the three commands for raise, lower and mute the sound into one script and added a notify-send command... and some if/then commands. wink

For example - this one from the OP:

#!/bin/sh

usage="usage: $0 -c {up|down|mute} [-i increment] [-m mixer]"
command=
increment=5%
mixer=Master

while getopts i:m:h o
do case "$o" in
    i) increment=$OPTARG;;
    m) mixer=$OPTARG;;
    h) echo "$usage"; exit 0;;
    ?) echo "$usage"; exit 0;;
esac
done

shift $(($OPTIND - 1))
command=$1

if [ "$command" = "" ]; then
    echo "usage: $0 {up|down|mute} [increment]"
    exit 0;
fi

display_volume=0

if [ "$command" = "up" ]; then
    display_volume=$(amixer set $mixer $increment+ unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
fi

if [ "$command" = "down" ]; then
    display_volume=$(amixer set $mixer $increment- unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
fi

icon_name=""

if [ "$command" = "mute" ]; then
    if amixer get Master | grep "\[on\]"; then
        display_volume=0
        icon_name="notification-audio-volume-muted"
        amixer set $mixer mute
    else
        display_volume=$(amixer set $mixer unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
    fi
fi

if [ "$icon_name" = "" ]; then
    if [ "$display_volume" = "0" ]; then
        icon_name="notification-audio-volume-off"
    else
        if [ "$display_volume" -lt "33" ]; then
            icon_name="notification-audio-volume-low"
        else
            if [ "$display_volume" -lt "67" ]; then
                icon_name="notification-audio-volume-medium"
            else
                icon_name="notification-audio-volume-high"
            fi
        fi
    fi
fi
notify-send " " -i $icon_name -h int:value:$display_volume -h string:synchronous:volume

The biggest part of the code is for defining the parameters used in the notify-send command in the last line. If you take a look at the parts with "$command" you can see how the amixer commands are built into the script.

So let's say for example you save this script in your ~/bin folder and name it "volscript" and make it executable via the command

chmod +x ~/bin/volscript

Then the command

volscript up

should do the same to the sound as

amixer sset PCM,0 5+

and additionally display a notification via notify-osd. This commands you can then use in your rc.xml.

I hope my explanations were helpful and you will get the notifications to work. Good luck! smile

Offline

#5 2011-03-30 22:30:37

bozhkov
#! Junkie
Registered: 2009-12-29
Posts: 464

Re: Notify-osd in openbox

bozhkov@crunchbang:~/bin$ sh volscript up
volscript: 62: notify-send: not found

I got that with this script.

Last edited by bozhkov (2011-03-30 22:32:12)

Offline

#6 2011-03-30 22:55:31

aiBo
#! CrunchBanger
Registered: 2010-11-08
Posts: 243

Re: Notify-osd in openbox

You have  to install libnotify-bin to use notify-send.

Offline

#7 2011-03-30 23:38:51

bozhkov
#! Junkie
Registered: 2009-12-29
Posts: 464

Re: Notify-osd in openbox

Thank you very much, aiBo, just one little thing - how to set the script to increase and decrease PCM levels with the up and down commands?
Edit: I found the solution, my slight addition was to add mixer2=PCM for up and down values:

#!/bin/sh

usage="usage: $0 -c {up|down|mute} [-i increment] [-m mixer]"
command=
increment=5%
mixer=Master
mixer2=PCM

while getopts i:m:h o
do case "$o" in
    i) increment=$OPTARG;;
    m) mixer=$OPTARG;;
    h) echo "$usage"; exit 0;;
    ?) echo "$usage"; exit 0;;
esac
done

shift $(($OPTIND - 1))
command=$1

if [ "$command" = "" ]; then
    echo "usage: $0 {up|down|mute} [increment]"
    exit 0;
fi

display_volume=0

if [ "$command" = "up" ]; then
    display_volume=$(amixer set $mixer2 $increment+ unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
fi

if [ "$command" = "down" ]; then
    display_volume=$(amixer set $mixer2 $increment- unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
fi

icon_name=""

if [ "$command" = "mute" ]; then
    if amixer get Master | grep "\[on\]"; then
        display_volume=0
        icon_name="notification-audio-volume-muted"
        amixer set $mixer mute
    else
        display_volume=$(amixer set $mixer unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
    fi
fi

if [ "$icon_name" = "" ]; then
    if [ "$display_volume" = "0" ]; then
        icon_name="notification-audio-volume-off"
    else
        if [ "$display_volume" -lt "33" ]; then
            icon_name="notification-audio-volume-low"
        else
            if [ "$display_volume" -lt "67" ]; then
                icon_name="notification-audio-volume-medium"
            else
                icon_name="notification-audio-volume-high"
            fi
        fi
    fi
fi
notify-send " " -i $icon_name -h int:value:$display_volume -h string:synchronous:volume

Last edited by bozhkov (2011-03-31 01:15:56)

Offline

#8 2011-03-31 07:55:44

aiBo
#! CrunchBanger
Registered: 2010-11-08
Posts: 243

Re: Notify-osd in openbox

Nice.
Your solution is a static one and should work fine.

But it already was possible with the original script: with the option "-m".
So the command would look like this:

volscript up -m PCM

Offline

#9 2011-03-31 12:07:30

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

Re: Notify-osd in openbox

Offline

#10 2011-03-31 15:36:42

bozhkov
#! Junkie
Registered: 2009-12-29
Posts: 464

Re: Notify-osd in openbox

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.
Server: acrobat

Debian Logo