SEARCH

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

You are not logged in.

#1 2011-01-28 22:37:47

chaanakya
#! Die Hard
Registered: 2010-12-30
Posts: 940

PulseAudio Volume Control with Media Keys

#!/bin/bash
declare -i CURVOL=`cat ~/.volume` #Reads in the current volume
if [[ $1 == "increase" ]]
then
CURVOL=$(($CURVOL + 3277)) #3277 is 5% of the total volume, you can change this to suit your needs.
fi
if [[ $1 == "decrease" ]]
then
CURVOL=$(($CURVOL - 3277))
fi
if [[ $1 == "mute" ]]
then
pactl set-sink-mute 0 1
exit
fi
if [[ $1 == "unmute" ]]
then
pactl set-sink-mute 0 0
exit
fi
if [[ $CURVOL -le 65540 && $CURVOL -ge 0 ]] # Check to see if the volume is a valid number (65540 was needed in this case because of how I rounded the increment)
then
pactl set-sink-volume 0 $CURVOL
echo $CURVOL > .volume # Write the new volume to disk to be read the next time the script is run.
exit
fi

Last edited by chaanakya (2011-01-29 22:49:15)

Offline

Help fund CrunchBang, donate to the project!

#2 2011-02-15 13:31:13

wudu83
New Member
Registered: 2011-02-15
Posts: 1

Re: PulseAudio Volume Control with Media Keys

Thanks, that helped me but I want to have only one script and other things, so i modified yours.
- All in one script
- It creates the mute and volume file if not existing
- It creates them in .pulse (I don't want them in my home directory)
- limits the volume to a valid number (in your version the volume can get invalid numbers: 65537 to 65539)
- Volume can reach exactly 0 or 65536

Here's my script:

#!/bin/bash
#### Create ~/.pulse/mute if not exists
ls ~/.pulse/mute &> /dev/null
if [[ $? != 0 ]]
then
    echo "false" > ~/.pulse/mute
fi

####Create ~/.pulse/volume if not exists
ls ~/.pulse/volume &> /dev/null
if [[ $? != 0 ]]
then
    echo "65536" > ~/.pulse/volume
fi

CURVOL=`cat ~/.pulse/volume`     #Reads in the current volume
MUTE=`cat ~/.pulse/mute`          #Reads mute state

if [[ $1 == "increase" ]]
then
    CURVOL=$(($CURVOL + 3277)) #3277 is 5% of the total volume, you can change this to suit your needs.
    if [[ $CURVOL -ge 65536 ]]
    then
        CURVOL=65536        
    fi
elif [[ $1 == "decrease" ]]
then
    CURVOL=$(($CURVOL - 3277))
    if [[ $CURVOL -le 0 ]]
    then
        CURVOL=0        
    fi
elif [[ $1 == "mute" ]]
then
    if [[ $MUTE == "false" ]]
    then
        pactl set-sink-mute 0 1
        echo "true" > ~/.pulse/mute
    exit    
    else
        pactl set-sink-mute 0 0
        echo "false" > ~/.pulse/mute    
    exit
    fi
fi

pactl set-sink-volume 0 $CURVOL
echo $CURVOL > ~/.pulse/volume # Write the new volume to disk to be read the next time the script is run.

Last edited by wudu83 (2011-02-15 14:00:11)

Offline

#3 2011-02-15 14:05:08

chaanakya
#! Die Hard
Registered: 2010-12-30
Posts: 940

Re: PulseAudio Volume Control with Media Keys

Just as an fyi...volumes above 65536 aren't technically invalid...it's just that you're amplifying the signal.  I might have actually modified the script after I put this up, to let it go up to exactly 65536, but I'm not sure big_smile.  Anyway, thanks for the feedback/modifications smile

Offline

#4 2011-08-01 11:26:55

jeetu
New Member
Registered: 2011-08-01
Posts: 1

Re: PulseAudio Volume Control with Media Keys

Offline

#5 2012-02-10 18:18:45

uriel1998
Member
From: Dayton, OH
Registered: 2012-02-10
Posts: 49
Website

Re: PulseAudio Volume Control with Media Keys

Offline

#6 2012-06-26 00:30:19

arman
Member
Registered: 2011-12-08
Posts: 27

Re: PulseAudio Volume Control with Media Keys

Thank you for this; it is exactly that for which I am looking!! smile

Offline

#7 2013-05-31 18:33:27

folti
#! Member
Registered: 2013-05-26
Posts: 82

Re: PulseAudio Volume Control with Media Keys

Last edited by folti (2013-05-31 18:35:09)

Offline

#8 2013-05-31 19:22:30

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: PulseAudio Volume Control with Media Keys

Yes.
Create empty files with the touch command:

touch ~/.pulse/.{mute,volume}

Offline

#9 2013-05-31 19:36:48

folti
#! Member
Registered: 2013-05-26
Posts: 82

Re: PulseAudio Volume Control with Media Keys

did i understand ok?

created
/home/folti/.pulse/mute
and
/home/folti/.pulse/volume

(here is the ls:)

folti@platon:~/.pulse$ ls
216c0d93934e66766ca72ac651a67716-card-database.tdb
216c0d93934e66766ca72ac651a67716-default-sink
216c0d93934e66766ca72ac651a67716-default-source
216c0d93934e66766ca72ac651a67716-device-volumes.tdb
216c0d93934e66766ca72ac651a67716-runtime
216c0d93934e66766ca72ac651a67716-stream-volumes.tdb
mute
volume
folti@platon:~/.pulse$ 

but, when i run the script zvuk:

folti@platon:~/scripts$ sh zvuk
zvuk: 4: zvuk: [[: not found
zvuk: 11: zvuk: [[: not found
/home/folti/.pulse/mute
/home/folti/.pulse/volume
zvuk: 19: zvuk: [[: not found
zvuk: 26: zvuk: [[: not found
zvuk: 33: zvuk: [[: not found
You have to specify a sink name/index and a volume
folti@platon:~/scripts$ 



i did

touch ~/.pulse/.{mute,volume}

and the uotput is the same:

folti@platon:~/scripts$ sh zvuk
zvuk: 4: zvuk: [[: not found
zvuk: 11: zvuk: [[: not found
/home/folti/.pulse/mute
/home/folti/.pulse/volume
zvuk: 19: zvuk: [[: not found
zvuk: 26: zvuk: [[: not found
zvuk: 33: zvuk: [[: not found
You have to specify a sink name/index and a volume
folti@platon:~/scripts$ 

i don't understand what am i doing wrong sad

Offline

#10 2013-05-31 19:41:25

folti
#! Member
Registered: 2013-05-26
Posts: 82

Re: PulseAudio Volume Control with Media Keys

Last edited by folti (2013-05-31 20:17:45)

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: bleh

Debian Logo