title: OS X Programmatically Set Default Output Device
body: <p>I have been attempting to change which audio device my computer sends sound to. My end goal is to create a program that can make my laptop output to its built-in speakers even when headphones are plugged into the headphone jack.</p>
  
  <p>I stumbled across <a href="https://github.com/deweller/switchaudio-osx" rel="noreferrer">this</a> project, but the methods it uses (specifically <code>AudioHardwareSetProperty</code>) are deprecated. It also just doesn't work (it will say it changed the output device, but sound will still go to my headphones).</p>
  
  <p>CoreAudio seems very poorly documented and I could not find ANY code online that did not use that function. I would go with the deprecated function if it did what I wanted, but it doesn't. I'm unsure weather it's broken or just doesn't do what I think it does, but that really doesn't matter in the end.</p>
  
  <p>I attempted to look at the comments on <code>AudioHardwareSetProperty</code> but all I found was this in the discussion section:</p>
  
  <blockquote>
    <p>Note that the value of the property should not be considered changed until the
                        HAL has called the listeners as many properties values are changed
                        asynchronously. Also note that the same functionality is provided by the
                        function AudioObjectGetPropertyData().</p>
  </blockquote>
  
  <p>This is obviously not true, since I know for a fact that <code>AudioObjectGetPropertyData</code> is used for <em>getting</em> information about <em>one specific audio device</em>.</p>
  
  <p>Is what I am trying to do possible with CoreAudio?</p>