9

How can I programmatically create a Multi-Output Device in Mac OS X?

The Audio Midi Setup program provides a GUI interface for creating one, but I would like to be able to create one in code.

I've found some resources already for creating aggregate devices, but multi-output devices function differently and I can't find anything on creating them. Here's what I've got so far:

2
  • Programmatically through Objective-C/Swift, or by AppleScripting an application?
    – jkdev
    Feb 24, 2016 at 22:32
  • @jkdev through Objective-C/Swift Feb 25, 2016 at 22:54

2 Answers 2

7

I had the same need to create a Multi Output Device programmatically. This example: http://daveaddey.com/?p=51 covers the needs.

I managed to do it by studying /Library/Preferences/Audio/com.apple.audio.SystemSettings.plist. This is the place where the Audio MIDI Setup saves the configuration (on my box, El Capitan).

Create a Multi-Output Device and an Aggregate Device and study the plist. They're pretty much the same, except the fact that the Aggregate Device has a master device, while the MOD does not.

Considering the example from Dave Addey: I for one, managed to create the MOD by removing the master device and adding my own devices as outputs. (in my case, Soundflower and the Default Output)

Besides this, add the "stacked" boolean key to the CF Dictionary. According to the CoreAudio sources, this key ensures that the same output is sent to all output channels, as opposed to the Aggregate Device which is not stacked, and combines multiple devices to make itself 'look' as a single device with a lot of channels.

Hope this helps.

3
  • Thank you! This saved me a lot of time.
    – Andy Hin
    Jun 11, 2017 at 0:08
  • Brilliant! I wonder if I can use the more modern AudioHardwareCreateAggregateDevice() or if it’s still a trip through the plugin interface? Jun 1, 2019 at 8:03
  • 2
    Yes! As of macOS 10.9 you can do it with AudioHardwareCreateAggregateDevice + kAudioAggregateDeviceIsStackedKey, although neither flavour of aggregate device support volume control which is a shame. Jun 3, 2019 at 4:42
5

This is basically @Andrei B.'s answer, with the linked [now dead] blog post code updated to use AudioHardwareCreateAggregateDevice() and the kAudioAggregateDeviceIsStackedKey symbol (and it's in swift, sorry, I didn't read the question):

func createMultiOutputAudioDevice(masterDeviceUID: CFString, secondDeviceUID: CFString, multiOutUID: String) -> (OSStatus, AudioDeviceID) {
    let desc: [String : Any] = [
        kAudioAggregateDeviceNameKey: "My Multi-Output Device",
        kAudioAggregateDeviceUIDKey: multiOutUID,
        kAudioAggregateDeviceSubDeviceListKey: [[kAudioSubDeviceUIDKey: masterDeviceUID], [kAudioSubDeviceUIDKey: secondDeviceUID]],
        kAudioAggregateDeviceMasterSubDeviceKey: masterDeviceUID,
        kAudioAggregateDeviceIsStackedKey: 1,
        ]

    var aggregateDevice: AudioDeviceID = 0
    return (AudioHardwareCreateAggregateDevice(desc as CFDictionary, &aggregateDevice), aggregateDevice)
}

Too bad multi output devices don't have volume control, this makes them not so useful when they become the default output device.

2
  • 3
    Thank you for "materialising" the dead link ;-)
    – Teejay
    Oct 14, 2019 at 23:31
  • 2
    With help from the wayback machine Oct 15, 2019 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.