Question

I'd like to be able to switch the sound output source in Mac OS X without any GUI interaction.

There are tools to do control the sound output, such as SoundSource and an applescript to open the preferences dialog.

What I am looking for is something that switches the preference instantly, like SoundSource but it has to be scriptable. The goal is to switch between my digital and analog output with one keystroke. I have a helper application that will launch a program or applescript on one keypress. All I need now is the applescript or application that switches the sound source quickly without any user interaction.

I'm willing to write some Objective-C if that is what it takes, but I'm pretty much a newbie at Cocoa development.

Do you have a one-click solution or can point me to a good tutorial on controlling sound system preferences from a Cocoa App or command line?

EDIT: I created a command-line application to do exactly this. You may download it at http://code.google.com/p/switchaudio-osx/downloads. Source code is available on the project site as well.

Was it helpful?

Solution

Don’t think of it in terms of preferences; there’s no centralized system preference framework for this sort of thing. I believe what you need to do is use Core Audio to set the kAudioHardwarePropertyDefaultOutputDevice and kAudioHardwarePropertyDefaultSystemOutputDevice properties of the AudioSystemObject (using AudioHardwareSetProperty()).

OTHER TIPS

I created a command-line application to do exactly this.

You may download it at http://code.google.com/p/switchaudio-osx/downloads. Source code is available on the project site as well.

UPDATE (Dec. 2014): the code is now hosted on github -- https://github.com/deweller/switchaudio-osx. And works just fine in Yosemite.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top