Fast switching playback devices using AutoItPublished: Thursday, 26 May 2011 15:49 Written by Ogri Hits: 14205
Not so long ago I bought a bluetooth stereo headset (Motorola S9-HD by the way, this one:
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:
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:
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.
Latest News
-
Saturday, 10 February 2018 18:48
Implementation of Windows Mail into Windows 10 version 1709. MAPI restored! -
Tuesday, 02 January 2018 16:40
Implementation of Windows Mail into Windows 10 version 1709 -
Friday, 18 November 2016 19:14
Reinstall Windows 10 without losing programs and files (Repair install) -
Thursday, 16 April 2015 19:17
Reinstall Windows 7 without losing programs and files (Repair install) -
Wednesday, 07 May 2014 14:08
Enabling Windows Mail in Windows 7 - retrospective review three years later
Articles Most Read
-
55049
Enabling Windows Mail in Windows 7 -
28741
Reinstall Windows 7 without losing programs and files (Repair install) -
27908
Migrating Windows 2000 / XP to a VMWare virtual machine -
19328
Windows XP Installation: The "34 minutes remaining" syndrome -
16058
How to determine whether my PC is running Windows 8 of 32 bit or 64 bit
Login
Guest Column
Recent comments
-
Check integrity of system files in Windows 7
-
강남출장마사지 27.01.2023 07:26
-
서울출장마사지 27.01.2023 02:18
Thanks designed for sharing such a nice idea, article is good, thats why i have read it entirely
-
-
How to determine whether my PC is running Windows 7 of 32 bit or 64 bit
-
Buy press releases 27.01.2023 17:19
I have been exploring for a little bit for any high-quality articles or blog posts in this kind of ...
-
Buy press releases 26.01.2023 14:01
I was curious if you ever thought of changing the layout of your website? Its very well written; I ...
-
-
How to determine whether my PC is running Windows 8 of 32 bit or 64 bit
-
수원출장마사지 27.01.2023 02:07
It's an remarkable piece of writing in support of all the internet people; they will obtain advantage ...
-
감성마사지 26.01.2023 05:01
I have read so many content concerning the blogger lovers but this post is in fact a pleasant paragraph ...
-
-
Implementation of Windows Mail into Windows 10 version 1709
-
bouppteckning dödsbo 26.01.2023 03:12
Do you have ɑ spam ρroblem on tuis website; Ι also am ɑ blogger, ɑnd I was wanting to know үoᥙr ...
-
-
Implementation of Windows Mail into Windows 10 version 1709. MAPI restored!
-
로미로미 26.01.2023 07:02
What's up, after reading this awesome paragraph i am too cheerful to share my know-how here with ...
-
-
Reinstall Windows 7 without losing programs and files (Repair install)
-
근처마사지 26.01.2023 03:13
Thank you for sharing your info. I really appreciate your efforts and I am waiting for your next post ...
-
의정부홈케어 26.01.2023 03:00
Howdy fantastic website! Does running a blog like this take a great deal of work? I have no expertise ...
-
Read more...