Jump to content

Simple Default Audio Device Toggling


sight92
 Share

Recommended Posts

Title

Just a simple Multi-Device Toggling script, everything else I saw involved writing into files the default entry, imo this is much much simpler.

Obviously it'll only work if your intention is to cycle between the devices 'till you find the one you want.

Also, this won't work if you have 'Show Disconnected/Disabled Devices' checked, this script reads from the ListView and then checks it against the 'Set Default' button.

It is unfortunate that Device Properties isn't accessible through the ListView, so there really is no truly universal way to single out disabled/disconnected devices from the selection process.

I initially had a popup window that lasted half-a-sec notifying the user of the device he'd just set, but it just bugged me so I took it off.

My setup only has 2 devices, but I edited it so that it cycles through all available devices.

Cheers

Run("RunDll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,0") ; Run the sound control applet | 0 - Playback / 1 - Recording

Local $handle = WinWaitActive("[CLASS:#32770]") ; Wait for it to be active before sending keystrokes. | CLASS refers to the sound control applet ClassID, if yours is different find the ID with WinSpy.
Local $index
Local $count = ControlListView($handle, "", "SysListView321", "GetItemCount")
if $count > 1 Then ; If there isn't another device, there's really no point, is there.
For $index = 0 To ($count - 1) ; Cycle through all the devices.
ControlListView($handle, "", "SysListView321", "Select", $index)
if ControlCommand($handle, "", 1002, "IsEnabled") = 0 Then ; Check to see if the 'Set Default' button >DOES NOT< lighten up | 1002 refers to the said button, if yours is different find the ID with WinSpy.
ExitLoop ; Seeing as it doesn't, we've found the default-set entry, meaning that we'll set it to the one after that.
EndIf
Next

$index += 1

if $index = $count Then ; If the default-set was the last entry, revert to the first.
$index = 0
EndIf

ControlListView($handle, "", "SysListView321", "Select", $index)

Send("!s") ; Send ALT+S Which Sets as default the selected entry

EndIf

WinClose($handle) ; Pull a Cobain and end it all

'Shame this forum cuts through tab-indentation.

Edited by sight92
Link to comment
Share on other sites

Shame this forum cuts through tab-indentation.

Run("RunDll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,0") ; Run the sound control applet | 0 - Playback / 1 - Recording

Local $handle = WinWaitActive("[CLASS:#32770]") ; Wait for it to be active before sending keystrokes. | CLASS refers to the sound control applet ClassID, if yours is different find the ID with WinSpy.
Local $index
Local $count = ControlListView($handle, "", "SysListView321", "GetItemCount")
If $count > 1 Then ; If there isn't another device, there's really no point, is there.
    For $index = 0 To ($count - 1) ; Cycle through all the devices.
        ControlListView($handle, "", "SysListView321", "Select", $index)
        If ControlCommand($handle, "", 1002, "IsEnabled") = 0 Then ; Check to see if the 'Set Default' button >DOES NOT< lighten up | 1002 refers to the said button, if yours is different find the ID with WinSpy.
            ExitLoop ; Seeing as it doesn't, we've found the default-set entry, meaning that we'll set it to the one after that.
        EndIf
    Next
    
    $index += 1

    If $index = $count Then ; If the default-set was the last entry, revert to the first.
        $index = 0
    EndIf

    ControlListView($handle, "", "SysListView321", "Select", $index)

    Send("!s") ; Send ALT+S Which Sets as default the selected entry

EndIf

WinClose($handle) ; Pull a Cobain and end it all

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...