keyboard volume changer
Posted: Sun 24 Apr 2011, 08:41
here's a script i made to change the volume from the keyboard
it uses amixer to change the volume and yaf-splash to display the status
here's how it looks
here's the script
as you can see in my case master front and pcm control the volume so that's what i'm changing
not all cards have the same channels so you might want to check which controls change the volume by running alsamixer in a terminal and messing around there for a while, then make the changes in the script
after you're done changing what's relevant you your sound card save the script somewhere in /usr/bin and chmod +x it. mine is called ali-vol
now to bind that to the keyboad.
assuming you are running openbox go to your ~/.config/openbox/rc.xml
and in the keyboard bindings add
i couldn't figure out how to get the media keys working on mine so instead of the XF86 audio keys i use control-alt-shift-up for volume up, down for volume down and left / right for mute/unmute
after you modified your rc.xml run
in a terminal and assuming you didn't mess anything up while adding that the script should work and properly display changes
if anyone manages to get the media keys working please let me know
it uses amixer to change the volume and yaf-splash to display the status
here's how it looks
here's the script
Code: Select all
#! /bin/bash
if [[ $1 -eq 1 ]]
then
P=`amixer sset 'Master Front' 1+ | grep 'Front Left:' | awk '{print $5}' | sed 's/\[/Master Front: /g' | sed 's/\]//g'`
M=`amixer sset 'PCM' 2+ | grep 'Front Left:' | awk '{print $5}' | sed 's/\[/PCM: /g' | sed 's/\]//g'`
yaf-splash -text "$P $M" -timeout 1
else if [[ $1 -eq 2 ]]
then
P=`amixer sset 'Master Front' 1- | grep 'Front Left:' | awk '{print $5}' | sed 's/\[/Master Front: /g' | sed 's/\]//g'`
M=`amixer sset 'PCM' 2- | grep 'Front Left:' | awk '{print $5}' | sed 's/\[/PCM: /g' | sed 's/\]//g'`
yaf-splash -text "$P $M" -timeout 1
else if [[ $1 -eq 3 ]]
then
P=`amixer sset 'Master Front',0 toggle | grep "Front Left:" | awk '{print $7}'`
if [[ ''$P'' == '[off]' ]]
then
P="Volume is off"
else
P="Volume is on"
fi
yaf-splash -text "$P" -timeout 1
fi
fi
fi
not all cards have the same channels so you might want to check which controls change the volume by running alsamixer in a terminal and messing around there for a while, then make the changes in the script
after you're done changing what's relevant you your sound card save the script somewhere in /usr/bin and chmod +x it. mine is called ali-vol
now to bind that to the keyboad.
assuming you are running openbox go to your ~/.config/openbox/rc.xml
and in the keyboard bindings add
Code: Select all
<keybind key="XF86AudioRaiseVolume">
<action name="Execute">
<command>ali-vol 1</command>
</action>
</keybind>
<keybind key="XF86AudioLowerVolume">
<action name="Execute">
<command>ali-vol 2</command>
</action>
</keybind>
<keybind key="XF86AudioMute">
<action name="Execute">
<command>ali-vol 3</command>
</action>
</keybind>
Code: Select all
<keybind key="C-A-S-Up">
<action name="Execute">
<command>ali-vol 1</command>
</action>
</keybind>
<keybind key="C-A-S-Down">
<action name="Execute">
<command>ali-vol 2</command>
</action>
</keybind>
<keybind key="C-A-S-Left">
<action name="Execute">
<command>ali-vol 3</command>
</action>
</keybind>
<keybind key="C-A-S-Right">
<action name="Execute">
<command>ali-vol 3</command>
</action>
</keybind>
Code: Select all
openbox --reconfigure
if anyone manages to get the media keys working please let me know