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:

# found with "pactl list sinks"
pactl set-default-sink $sinkname
for inputid in `pactl list short sink-inputs | cut -f1`; do
    pactl move-sink-input $inputid $sinkname

Written by Christian Weiske.

Comments? Please send an e-mail.