Logitech USB Headset volume is low [Ubuntu] – Fixing this with a script

There is a nasty bug in Ubuntu – even in 10.* and 11.*! But there is a simple fix via alsamixer. The problem is that the volume is always near 0 when when plugging in the device again. So this mini post is how to find out the command to increase the volume which you can execute e.g. on startup. First, you need to find out which card the device has in my case its number 1, then you need to list the controls:

$ amixer -c 1 scontrols
Simple mixer control ‘Speaker’,0
Simple mixer control ‘Mic’,0

As last step increase the volume of one or more control:
$ amixer -c 1 sset ‘Speaker’,0 90% 90%
Simple mixer control ‘Speaker’,0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left – Front Right
Limits: Playback 0 – 44
Mono:
Front Left: Playback 40 [91%] [2.72dB] [on]
Front Right: Playback 40 [91%] [2.72dB] [on]

Now there is only one problem: how to automatically switch from 0 to my USB device 1? Here is the solution

pacmd list-sinks | grep index
pacmd set-default-sink

or the full script:
amixer -c 1 sset ‘Speaker’,0 70% 70%
amixer -c 1 sset ‘Mic’,0 70% 70%

# switch mic
sources=($(pacmd list-sources | grep index | awk ‘{ if ($1 == “*”) print “1”,$3; else print “0”,$2 }’))
[[ ${sources[0]} = 0 ]] && swap=${sources[1]} || swap=${sources[5]}
echo $swap
pacmd set-default-source $swap &> /dev/null

# switch audio
sinks=($(pacmd list-sinks | grep index | awk ‘{ if ($1 == “*”) print “1”,$3; else print “0”,$2 }’))
[[ ${sinks[0]} = 0 ]] && swap=${sinks[1]} || swap=${sinks[3]}
pacmd set-default-sink $swap &> /dev/null

Now have a look here where it is described how to call this script when the device is plugged in.