Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Sound (or other) System Preferences in Mac OS X

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.

like image 391
Devon Avatar asked Oct 04 '08 12:10

Devon


2 Answers

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.

like image 195
Devon Avatar answered Oct 13 '22 12:10

Devon


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

like image 42
Jens Ayton Avatar answered Oct 13 '22 13:10

Jens Ayton