Audio Device Switcher
An audio device switcher written in Batch and Cscript using SoundVolumeView.
A collection of scripts that can set the default audio device, check the current default device, or switch between two devices.
Content
Dependencies
- SoundVolumeCommandLine v1.25 by Nir Sofer - Website.
The scripts may work with other versions, but this is the version that was used during development.
Installation
- Download and unpack the dependency.
- Download the desired scripts and
variables.csv. The scripts are intentionally separate so you can download only the ones you need.
Place the files in the same folder as svcl.exe for ease of use.
- Update the
variables.csv file to fit your setup:
SoundVolumeView,<relative path to svcl.exe>
TIMEOUT,<how many seconds information popups wait before automatically closing>
COLUMN,<name of the column in SoundVolumeView that indicates your default device>
DEFAULT,<keyword that appears in COLUMN for your default device>
S_DEVICE,<name of 1st audio device>
H_DEVICE,<name of 2nd audio device>
S_VOLUME,<default volume for 1st device>
H_VOLUME,<default volume for 2nd device>
Variables are currently configured to switch between a Headset and Speakers. File names and code comments reflect this, but you can switch any two devices.
Scripts
CheckDevice.bat
Displays which of the two devices is currently set as default in a popup. Shows an error if the current default isn’t one of the two.
Required variables:
- SoundVolumeView, TIMEOUT, COLUMN, DEFAULT, H_DEVICE, S_DEVICE
Script behaviour:
- Reads variables from
VARS_PATH.
- Uses
SoundVolumeView to get the value of COLUMN for S_DEVICE and H_DEVICE.
- Determines which device matches the
DEFAULT keyword.
- Displays info popup for
TIMEOUT seconds showing the current default device.
SwitchDevice.bat
Switches the default device between the two options and sets the corresponding volume. If the current default device isn’t one of the options, an error message is displayed.
Required variables:
- SoundVolumeView, TIMEOUT, COLUMN, DEFAULT, H_DEVICE, S_DEVICE, H_VOLUME, S_VOLUME
Script behaviour:
- Reads variables from
VARS_PATH.
- Uses
SoundVolumeView to get the value of COLUMN for S_DEVICE and H_DEVICE.
- Determines which device matches the
DEFAULT keyword.
- Uses
SoundVolumeView to switch default device to the other device.
- Uses
SoundVolumeView to set the new default device’s volume to the corresponding default (H_VOLUME or S_VOLUME).
- Displays info popup for
TIMEOUT seconds confirming the switch.
PromptSwitch.bat
Checks the current default device and prompts the user whether to switch to the other device. If “ok” is selected, it switches and adjusts volume. If the current default isn’t one of the two devices, an error popup is shown.
Required variables:
- SoundVolumeView, TIMEOUT, COLUMN, DEFAULT, H_DEVICE, S_DEVICE, H_VOLUME, S_VOLUME
Script behaviour:
- Reads variables from
VARS_PATH (relative path to variables.csv, declared inside the script)
- Uses
SoundVolumeView to get the value of COLUMN for S_DEVICE and H_DEVICE.
- Determines which device matches the
DEFAULT keyword.
- Displays a prompt popup asking the user if they want to switch.
- If “ok”:
- Switches the default device to the other device using
SoundVolumeView.
- Sets the new device volume (
H_VOLUME or S_VOLUME)
- Displays info popup for
TIMEOUT seconds confirming the switch.
- If “cancel”: exits without making changes.
SwitchHeadset.bat
Sets H_DEVICE as the default audio device and adjusts volume accordingly, regardless of the current default.
Required variables:
- SoundVolumeView, TIMEOUT, H_DEVICE, H_VOLUME
Script behaviour:
- Reads variables from
VARS_PATH (relative path to variables.csv, declared inside the script)
- Switches default device to
H_DEVICE using SoundVolumeView.
- Sets volume to
H_VOLUME.
- Displays info popup for
TIMEOUT seconds confirming the change.
SwitchSpeakers.bat
Sets S_DEVICE as the default audio device and adjusts volume accordingly, regardless of the current default.
Required variables:
- SoundVolumeView, TIMEOUT, S_DEVICE, S_VOLUME
Script behaviour:
- Reads variables from
VARS_PATH (relative path to variables.csv, declared inside the script)
- Switches default device to
S_DEVICE using SoundVolumeView.
- Sets volume to
S_VOLUME.
- Displays info popup for
TIMEOUT seconds confirming the change.
Usage
- Run the desired script to check or switch your default audio device.
[!TIP]
Create a shortcut to the script on your desktop, open its properties, and set Run to Minimized. This allows it to run in the background, showing only the final popup result.
Run the script via the shortcut instead of directly to avoid multiple console windows.
If your keyboard or mouse has programmable buttons, you can assign them to run these shortcuts, allowing switching/checking audio devices without opening folders or the desktop.
评论