views:

2994

answers:

4

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.

+4  A: 

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()).

Ahruman
This looks promising. I don't know enough Cocoa (yet) for this to make sense, but it looks like the right track.
Devon
+2  A: 

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.

Devon
That's awesome, thanks for posting this as open source too, I'm sure many others will appreciate it!
Jay
A: 

I just wanted to thank you for the command-line app. It makes a great default audio interface picker that I can load into a login hook.

A: 

thanks, this is also extremely useful for lab management via Remote Desktop.