Script to switch Linux sound output

At work I often switch my audio output between the USB headset and the normal speakers. Switching means:

  1. Start pavucontrol (PulseAudio Volume Control)
  2. Mark the USB headset output device as default ("Set as fallback")
  3. Tell all applications that are playing music to use the USB headset as output.

Luckily, this is Linux, so this is scriptable:

#!/bin/sh
 
# found with "pactl list sinks"
sinkname=alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo
 
pactl set-default-sink $sinkname
 
for inputid in `pactl list short sink-inputs | cut -f1`; do
    pactl move-sink-input $inputid $sinkname
done

Written by Christian Weiske.

Comments? Please send an e-mail.