Changing default audio device
#1
TheIceMan
Posted 21 February 2005 - 05:21 AM
Is there any way to create a script that will automatically change the device, run a particular program (for example, tv tuner software that is incompatible with my USB audio out), then change the audio device back to what it was originally...?
Any suggestions or help would be very much appreciated!
#2
Posted 21 February 2005 - 07:36 AM
My script is for WinXP, so if you have another OS, you may need to change window titles etc.
Run, mmsys.cpl
Sleep, 100
WinWait, Sounds and Audio Devices Properties
IfWinNotActive, Sounds and Audio Devices Properties WinActivate, Sounds and Audio Devices Properties
WinWaitActive, Sounds and Audio Devices Properties
Send, ^{Tab}
Sleep, 100
Send, ^{Tab}
Sleep, 100
WinWait, Sounds and Audio Devices Properties
IfWinNotActive, Sounds and Audio Devices Properties WinActivate, Sounds and Audio Devices Properties
WinWaitActive, Sounds and Audio Devices Properties
Send, {Down}
Sleep, 50
Send, !A
Sleep, 100
Send, {Enter}As a sidenote - this script switches between two audio devices and I don't have a clue which device it would select if you have more.
#3
BoBo
Posted 21 February 2005 - 07:54 AM
SoundSet
--------------------------------------------------------------------------------
Changes various settings of a sound device (master mute, master volume, etc.)
SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]
If this parameter is omitted, it defaults to 1 (the first sound device), which is usually the system's default device for recording and playback. Specify a number higher than 1 to operate upon a different sound device.
Might be of interest.
8)
#4
Posted 21 February 2005 - 09:36 AM
SoundSet
--------------------------------------------------------------------------------
Changes various settings of a sound device (master mute, master volume, etc.)
SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]
If this parameter is omitted, it defaults to 1 (the first sound device), which is usually the system's default device for recording and playback. Specify a number higher than 1 to operate upon a different sound device.
SoundSet only changes volume etc. of a selected device, but it does not change which device is active.
#5
adlib
Posted 01 March 2005 - 05:58 PM
Sidenote tho, the !A-command is irrelevant as the simple enter-press does apply aswell as close the window. Makes it all slightly faster
Also, why use the sleep-command when you will be waiting for the window to emerge anyway?
#6
Posted 24 November 2007 - 11:28 AM
I had always wanted to do this, but i had no idea about this part
Run, mmsys.cpl
Thanks Alot for posting this.
I changed it a Lil bit on mine
Send, ^{Tab 2}
Sleep, 100High Five!!
#7
Posted 14 May 2008 - 12:19 AM
Windows stores the default playback device under the "HKEY_CURRENT_USER\ Software\Microsoft\Multimedia\Sound Mapper\Playback" key.
Doing something like this will switch between my onboard realtek and creative audigy se sounds cards that I have on my rig:
; Toggle Sound Devices
!+s::
RegRead, Device, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback
if(Device = "Realtek HD Audio output")
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, Sound Blaster Audigy
Device := "Audigy"
}
else
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, Realtek HD Audio output
Device := "Realtek"
}
ToolTip, % "Sound Device: " Device
SetTimer, ResetToolTip, 1000
return
; Clear the ToolTip
ReSetToolTip:
ToolTip
SetTimer, ReSetToolTip, Off
return
Change the "if(Device = ...)" line with your sound card names.
Unfortunately I haven't found a way to make windows update all the programs running with the new default sound card device. That way even if I change the default by hand I have to restart my processes to update them with the new sound device.
#8
Posted 14 May 2008 - 02:13 AM
#9
Posted 30 December 2008 - 12:39 AM
#10
Beyondinferno
Posted 10 January 2009 - 03:42 AM
#11
Beyondinferno
Posted 10 January 2009 - 03:43 AM
#12
Guests
Posted 06 February 2009 - 06:12 AM
i'm using xp sp3
#13
Guests
Posted 17 April 2009 - 03:14 PM
Here I've set it to F5 setting the first device on the list as default and F6 setting the second as default. Tweak it as needed.
#F5::
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down}
ControlClick,&Set Default
ControlClick,OK
return
#F6::
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down 2}
ControlClick,&Set Default
ControlClick,OK
return
#14
Posted 21 September 2009 - 02:54 AM
This will set the first device active if it isn't already.
If the first device is active then it will activate the 3rd device.
Additionally once a device is picked it plays a sound so you know which device is selected.
^+`::
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down}
ControlGet, isEnabled, Enabled,,&Set Default
if(!isEnabled)
{
ControlSend,SysListView321,{Down 2}
}
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
SoundPlay, *-1
return
#15
Posted 23 November 2009 - 11:00 PM
The function below takes "device" as it appears in mmsys.cpl and looks for it in the combobox. If it finds it it changes the device and returns true. Otherwise it returns false.
I do use the registry first, however, to check whether the current device is the one we are trying to switch to since, while setting the registry value doesn't change the real sound device, changing the sound device DOES reflect in the registry.
ChangeSoundDevice(device)
{
window=Sounds and Audio Devices Properties
success := false
RegRead, registryDevice, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback
registryDevice = %registryDevice%
if registryDevice = %device%
{
success := true
}
else
{
Run control mmsys.cpl`,`,2
WinWait, Sounds and Audio Devices Properties,,5
ControlSend,ComboBox1,{Home},%window%
CurrentDevice=
Loop
{
ControlGetText,outputs,ComboBox1,%window%
; Trimming spaces
outputs = %outputs%
if outputs = %device%
{
success := true
break
}
else if outputs<>%CurrentDevice%
{
;MsgBox, Not equal: "%CurrentDevice%" <> "%outputs%"
CurrentDevice = %outputs%
}
else
{
;MsgBox, Equal: "%CurrentDevice%" == "%outputs%"
OSD("Device not found:" . device)
break
}
ControlSend,ComboBox1,{Down},%window%
}
Send ^{Enter}
}
return success
}
Thanks,
Vitaly
P.S The code works in XP, I assume some changes would be needed under Vista/7




