Skip to content

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.

License

Notifications You must be signed in to change notification settings

ElenaChes/batch-audio-device-switcher

Repository files navigation

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

  1. 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

  1. Download and unpack the dependency.
  2. Download the desired scripts and variables.csv. The scripts are intentionally separate so you can download only the ones you need.

Tip

Place the files in the same folder as svcl.exe for ease of use.

  1. 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>

Note

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:

  1. Reads variables from VARS_PATH.
  2. Uses SoundVolumeView to get the value of COLUMN for S_DEVICE and H_DEVICE.
  3. Determines which device matches the DEFAULT keyword.
  4. 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:

  1. Reads variables from VARS_PATH.
  2. Uses SoundVolumeView to get the value of COLUMN for S_DEVICE and H_DEVICE.
  3. Determines which device matches the DEFAULT keyword.
  4. Uses SoundVolumeView to switch default device to the other device.
  5. Uses SoundVolumeView to set the new default device's volume to the corresponding default (H_VOLUME or S_VOLUME).
  6. 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:

  1. Reads variables from VARS_PATH (relative path to variables.csv, declared inside the script)
  2. Uses SoundVolumeView to get the value of COLUMN for S_DEVICE and H_DEVICE.
  3. Determines which device matches the DEFAULT keyword.
  4. Displays a prompt popup asking the user if they want to switch.
  5. 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.
  6. 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:

  1. Reads variables from VARS_PATH (relative path to variables.csv, declared inside the script)
  2. Switches default device to H_DEVICE using SoundVolumeView.
  3. Sets volume to H_VOLUME.
  4. 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:

  1. Reads variables from VARS_PATH (relative path to variables.csv, declared inside the script)
  2. Switches default device to S_DEVICE using SoundVolumeView.
  3. Sets volume to S_VOLUME.
  4. Displays info popup for TIMEOUT seconds confirming the change.

Usage

  1. 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.

Tip

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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks