Switching to an alternate speaker output using software only?

Hippo Man

Hippo Man
I have my headphones attached through my MacBook Pro's headphone jack. I have a USB connection to my speakers.

In some cases, I'd like to switch my computer's default sound output from the headphone port to the USB speaker port using software only.

In other words, I want to do this without any manual intervention at all: i.e., via an AppleScript, an ASOC program, or some other kind of software.

Could someone point me to some docs which describe how this can be done?

Thanks in advance.
.​
 
Have you tried using LineIn, a small utility from Rogue Amoeba? Or, perhaps more simply, using the Volume menu extra, Option-click the menu and choose input and output.
 
Thank you, but I want this to be fully automated (no human interaction).

In any case, I figured out a solution. The following AppleScript illustrates. Suppose I have two sound outputs. The first one is for my headphones, the second one is for my speaker.

Code:
on setSoundOutput(whichItem)
	tell application "System Preferences"
		reveal anchor "output" of pane id "com.apple.preference.sound"
	end tell
	tell application "System Events" to tell (table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences")
		select row whichItem
	end tell
	tell application "System Preferences" to quit
end setSoundOutput

setSoundOutput(1)  -- switches to headphones
setSoundOutput(2)  -- switches to speakers

.​
 
Back
Top