title: Change OS X system volume programmatically
body: <p>How can I change the volume programmatically from Objective-C?</p>
  
  <p>I found this question, <em><a href="https://stackoverflow.com/questions/5286092/controlling-os-x-volume-in-snow-leopard">Controlling OS X volume in Snow Leopard</a></em> which suggests to do:</p>
  
  <pre><code>Float32 volume = 0.5;
  UInt32 size = sizeof(Float32);
  
  AudioObjectPropertyAddress address = {
      kAudioDevicePropertyVolumeScalar,
      kAudioDevicePropertyScopeOutput,
      1 // Use values 1 and 2 here, 0 (master) does not seem to work
  };
  
  OSStatus err;
  err = AudioObjectSetPropertyData(kAudioObjectSystemObject, &amp;address, 0, NULL, size, &amp;volume);
  NSLog(@"status is %i", err);
  </code></pre>
  
  <p>This does nothing for me, and prints out <code>status is 2003332927</code>.</p>
  
  <p>I also tried using values <code>2</code> and <code>0</code> in the <code>address</code> structure, same result for both.</p>
  
  <p>How can I fix this and make it actually decrease the volume to 50%?</p>