Control specific audio device with amixer and i3block

I wrote another blocklet to be able to control my USB headset, next to my normal audio output. So that I was able to control my headset volume and PC speakers at the same time.

You can identify the audio device you would like to control with:

1
cat /proc/asound/cards

The output looks like that:

In my case, I was interested in the USB Audio Device called “C-Media”, which you will also find in the script itself. (Just take the first word, of your device name, from the second row)

The volume can be easily controlled by scrolling up/down over the icon.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

CARD=$(awk '$1 == "C-Media" {print f} {f=$1}' /proc/asound/cards)
VOLUME=$(amixer -M -c ${CARD} | grep -E -o '[0-9]{1,3}?%' | head -1)

if [ $BLOCK_BUTTON == '4' ]
then
amixer -D pulse sset Master 5%+ unmute -q
VOLUME=$(amixer -M -c ${CARD} | grep -E -o '[0-9]{1,3}?%' | head -1)
echo "<span foreground=\"#00FF00\">🎧 ${VOLUME}</span>"
fi

if [ $BLOCK_BUTTON == '5' ]
then
amixer -D pulse sset Master 5%- unmute -q
VOLUME=$(amixer -M -c ${CARD} | grep -E -o '[0-9]{1,3}?%' | head -1)
echo "<span foreground=\"#00FF00\">🎧 ${VOLUME}</span>"
else
echo "<span foreground=\"#00FF00\">🎧 ${VOLUME}</span>"
fi