Sunday, 30 June 2019

How do I manage multiple audio playback devices on Windows Vista/7?


I've got speakers (audio in) and headphones (USB headset with it's own soundcard) connected to my desktop computer. Under Windows 7, I can right-click the Audio Mixer and select Playback Devices and toggle between my these devices.


Is there an easier way, perhaps a keyboard shortcut, that would make it easier to toggle? I'm working in an shared space were sometimes I want headphones to avoid annoying other people, but at other times speakers are OK. I want to be able to toggle quickly. In an ideal world, the solution to my question would work in Vista too.



Answer



The solution to all your nagging Windows automation problems: AutoIt!


Put this AutoIt and compile it


;-----Configuration-----
;The title of the sound config window.
Dim $ConfigWindowTitle = "Sound"
;-----End of configuration----

Dim $ItemNumber = 1
If $CmdLine[0] >= 1 Then ;If we have a parameter...
$ItemNumber = $CmdLine[1] ;...we should press the button the specified number of times.
EndIf

Run("control mmsys.cpl") ;Run the sound control applet and hide it.

WinWaitActive($ConfigWindowTitle) ;Wait for it to be active before sending keystrokes.

Send("{TAB}{TAB}{TAB}{TAB}") ;Put the focus on the list

For $i = 1 to $ItemNumber Step 1
Send("{DOWN}")
Next

Send("!s") ;Press Alt + S to set the selected device as the default.
WinClose($ConfigWindowTitle)

Now create a shortcut, and in the Target put the path to the compiled executable. For an argument, put the number of the sound device in the list that you want to switch to. (to switch to the top item in the list, put 1, the second item in the list, put 2, etc). If you want a keyboard shortcut, use the Shortcut Key field in the shortcut's properties window.


I'd been looking for something to do what you wanted to do, and found that there's no programmatic way that you can switch audio devices in Vista/7. It's just not something that Microsoft decided that programmers need to do, so I make this script to automate the process. It's not the best since it pops up the window in order to change the device (necessary), but it makes it possible to create shortcuts to change the output device for your sound.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...