title: Manually changing the sound output device on linux
body: <p>If you haven't heard of SoundSwitch, its an app for windows that allows you to switch sound output/input devices with a keyboard shortcut. I've made a similar app for linux, but I cant get it to work properly. The majority of the app is done, and if you want to see the full code, its here: <a href="https://github.com/boskobs/sound-Source-Switch-4-Linux" rel="nofollow noreferrer">https://github.com/boskobs/sound-Source-Switch-4-Linux</a>
  Bellow is the part responsible for applying the changes:</p>
  
  <pre><code>   os.system("pacmd set-default-sink " + str(nextindex))
     output = subprocess.getoutput("pacmd list-sink-inputs")
     for item in output.split("\n"):
        if "index:" in item:
           inputindex = item.strip().replace("index: ","")
           os.system("pacmd move-sink-input " + str(inputindex) + " " + str(nextindex))
  </code></pre>
  
  <p>It changes the default sound output device, and transfers all of the current apps to that device. The problem occurs when I exit an app and switch the output device. Next time I start that app, the device it outputs sound to is the old one that was active before the switch. How can I make the new default output device really work as a default?</p>