Not so long ago I bought a bluetooth stereo headset (Motorola S9-HD by the way, this one:

Ogri's Playground - ogri.me | Bluetooth stereo headset Motorola S9-HD

Cool sound, built-in microphone. I'm very happy about the device and can recommend it to anyone). Paired the headset with my laptop and have been enjoying the brilliant sound quality. Sometimes I've also been connecting my good old wired headphones, for example, when forget to charge the battery of the new ones. The process of switching playback devices is not so time-consuming: right-click on the Speaker icon in the system tray -> select Playback Devices -> in the Playback tab of the Sound dialog choose the appropriate device and then click the Set Default button. But still it's annoying to perform this sequence every time you want to pass to different device, so I was wondering if there is an easy way to automate it.

The utility AutoIt is perfectly matched for this purpose (you can download it for free at the official site). Also the appropriate script has been found in the Web, here it is:

 ;-----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)

Copy this code to a text file and save it with the extension .au3. For example, toggle-playback.au3. Place it to the scripts folder of AutoIt3, I used an existing folder Examples. Then open the Sound dialog as described above. Mine looks like this:

Ogri's Playground - ogri.me | Sound -> Playback Dialog

I'm interested in first two devices. Bluetooth Audio Device - this is the headset, number 1 in the list. Number 2 - built-in speakers and sound card output. We'll need these numbers for further customization, so let's remember them.

From now on there are two possible alternatives.

1. Create two (or more - according to the number of switching devices) text files with an extension typical for console batch files - .cmd or .bat. Let's name them, for example, Bluetooth.cmd and Speakers.cmd. Open them for editing and type the following code.

Bluetooth.cmd file:

echo off
D:\Common\AutoIt3\AutoIt3_x64.exe D:\Common\AutoIt3\Examples\toggle-playback.au3 1

D:\Common in my case - the path to the folder AutoIt3. Replace it with your own. I've been also using the 64-bit version of AutoIt, owners of 32-bit system are to replace AutoIt3_x64.exe with AutoIt3.exe. The command itself, as is clear, uses two parameters. The first one is the script file name (including full path), and the second parameter is the serial number of an appropriate playback devices in the list, as clarified earlier.

Similarly, Speakers.cmd file will contain exactly the same code, except that the value of the second parameter is 2:

echo off
D:\Common\AutoIt3\AutoIt3_x64.exe D:\Common\AutoIt3\Examples\toggle-playback.au3 2

Now launching of each batch file will activate the appropriate playback device.

2. The folder Aut2Exe contains utility of the same name for compilation of .au3 script files to an executable. It is extremely simple and easy to use. It's required to fill input boxes with the source script file, path and name of exe-file, and optionally - assign an icon and bit capacity:

Ogri's Playground - ogri.me | Program Aut2Exe

Press the Convert button. The file TogglePlayback.exe will appear in the subfolder Examples.

Then, as in the first option, create two batch files Bluetooth.cmd and Speakers.cmd. Since both the functionality of AutoIt and the script are already built into TogglePlayback.exe, it's enough to run it with a single parameter - the number of your device. Content of Bluetooth.cmd is:

echo off
D:\Common\AutoIt3\Examples\TogglePlayback.exe 1

Code of Speakers.cmd, respectively -

echo off
D:\Common\AutoIt3\Examples\TogglePlayback.exe 2

That's it. Let's enjoy the opportunity to switch the sound between playback devices in one click.

Actually, AutoIt is a powerful tool for automating of various system processes. I would recommend to both myself and you to explore its functionality. But use it with reasonable care, get well-tested scripts from trusted sources to avoid potential issues in you system.

Add comment


By working with this site, you agree to our use of cookies necessary to keep the settings you select, as well as for the normal operation of Google services.
More Information OK