My two cents.
Of all the options listed here (and in linked answers), only the one with pavucontrol
gives any effect in my case. But it's too inconvenient, in my opinion.
I have 3 sound devices (that output sound), so earlier I had a script for switching cyclically between 2 of them (the third, with index 0, is no interest to me, so I always skip it). This was done with the following script:
#!/usr/bin/env bash
sinks_indices=($(pacmd list-sinks | grep index | \
awk '{ print $NF }'))
sinks_activity=($(pacmd list-sinks | grep index | \
awk '{ if ($1 == "*") print "1"; else print "0" }'))
inputs=($(pacmd list-sink-inputs | grep index | awk '{print $2}'))
# find active sink
active_idx=0
for i in ${sinks_activity[*]}
do
if [ $i -eq 0 ]
then active_idx=$((active_idx+1))
else break
fi
done
# switch to next sink
swap_idx=$(((active_idx+1)%${#sinks_activity[@]}))
# skip sink 0 because it's not used in my system
if [ $swap_idx -eq 0 ]; then
swap_idx=$(((swap_idx+1)%${#sinks_activity[@]}))
fi
swap=${sinks_indices[$swap_idx]}
pacmd set-default-sink $swap &> /dev/null
for i in ${inputs[*]}; do pacmd move-sink-input $i $swap &> /dev/null; done
It turned out that this script works. There is still one problem with it: when you reboot a system (or even start another application), the sound is output to any of the 2 devices unpredictably (at least I could not figure out the logic). But once you run the script, the sound gets output to whatever device you need.
It's very handy to assign it to a hotkey, so just one movement separates you from switching to another device (a lot more convenient that going to the menu; in 16.04 it was far better, the sound device checker was not so deep).
There is a similar problem with microphone, I was able to solve it by using pacmd list-source-outputs
, pacmd set-default-source
and pacmd move-source-output
.
And just a note: when booting from 20.04 Live DVD, the problems (at least with switching between speakers/headphones) simply do not occur. Maybe it makes sense to just reinstall from scratch, hmmm...