Return to Level1Techs.com

Ubuntu 18.04 - how do I change my audio device between headphones and Line Out, via the command line?

Hi!

I have a minor quality of life question. I have a set of Logitech USB headphones (actually a headset of headphones + mic, but anyway) and sometimes I want my audio to go through them, and sometimes I want it through my PC speakers connected to Line Out. When I want to swap, I need to open the Settings GUI, go down to Sound, and change my Output Device.

I’d like to be able to do this from the command line. Could anyone tell me where to look for that? Ultimately I’d like to be able to assign a hotkey to instantly swap back and forth, but to start I’d just like to be able to command it from one to the other. I always hear folks talk about how in Linux you can do everything via the command line, but I’m going crazy here trying to figure out how to actually do it.

Thanks!

Does this help?: https://unix.stackexchange.com/a/67398

1 Like

Thank you! I now have a shell script sitting in my home directory which is:

newSink="$1"

pactl list short sink-inputs|while read stream; do
    streamId=$(echo $stream|cut '-d ' -f1)
    echo "moving stream $streamId"
    pactl move-sink-input "$streamId" "$newSink"
done

I have now bound two keyboard keys to do ~/soundswapper.sh 0 and ~/soundswapper.sh 1 which work perfect!

2 Likes

Oh my, this is noice :slight_smile: