When searching for "XBMC change system volume" this question pops up as the first result. The current answers are not bad, but with the newer versions of XBMC it can be solved differently with script execution.
By editing the keyboard.xml
file you can change the keybindings to execute scripts. Location of keyboard.xml on all systems
I created a new keyboard.xml
file in /home/USER/.xbmc/userdata/keymaps/
with the following content:
<keymap>
<global>
<keyboard>
<volume_mute>RunScript(/home/USER/Scripts/mute.py)</volume_mute>
<volume_down>RunScript(/home/USER/Scripts/lower_volume.py)</volume_down>
<volume_up>RunScript(/home/USER/Scripts/raise_volume.py)</volume_up>
</keyboard>
</global>
</keymap>
This overrides the default behaviour of changing the XBMC sound levels with executing a script. For Ubuntu, I created a directory with various scripts in my home directory (scripts).
Contents of the files:
mute.py
#!/usr/bin/python
import subprocess
subprocess.call( "amixer -D pulse set Master 1+ toggle", shell=True )
lower_volume.py
#!/usr/bin/python
import subprocess
subprocess.call( "amixer -D pulse sset Master 5%-", shell=True )
raise_volume.py
#!/usr/bin/python
import subprocess
subprocess.call( "amixer -D pulse sset Master 5%+", shell=True )
Then make the files executable with chmod +x Scripts/*
. The minus and plus button on the numpad can still lower/raise the volume of XBMC, but those can also be disabled with changing the keyboard.xml
.