An open API service indexing awesome lists of open source software.

https://github.com/jaries23/sounddeviceswitcher

This batch script toggles between two predefined audio devices (e.g., earphones and speakers) using NirCmd and PowerShell. It checks if both devices are connected, determines the current default playback device, and switches to the other device accordingly. A notification balloon informs the user of the change or connection issue.
https://github.com/jaries23/sounddeviceswitcher

batchfile nircmd powershell

Last synced: about 1 month ago
JSON representation

This batch script toggles between two predefined audio devices (e.g., earphones and speakers) using NirCmd and PowerShell. It checks if both devices are connected, determines the current default playback device, and switches to the other device accordingly. A notification balloon informs the user of the change or connection issue.

Awesome Lists containing this project

README

          

# ๐ŸŽง SoundDeviceSwitcher

> ๐Ÿ”ฝ English instructions are available below.

Windows์—์„œ ๋‘ ๊ฐœ์˜ ์˜ค๋””์˜ค ์žฅ์น˜(์˜ˆ: ์ด์–ดํฐ๊ณผ ์Šคํ”ผ์ปค)๋ฅผ **์Šค๋งˆํŠธํ•˜๊ฒŒ ์ „ํ™˜**ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฐ์น˜ ์Šคํฌ๋ฆฝํŠธ์ž…๋‹ˆ๋‹ค.

๋‹จ์ˆœํ•œ ํ† ๊ธ€์ด ์•„๋‹Œ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ **์ง€๋Šฅ์ ์ธ ๊ธฐ๋Šฅ**์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค:

- โœ… **๋‘ ์žฅ์น˜๊ฐ€ ๋ชจ๋‘ ์—ฐ๊ฒฐ๋œ ๊ฒฝ์šฐ์—๋งŒ ์ „ํ™˜ ์‹คํ–‰**
- ๐Ÿ” ํ˜„์žฌ ๊ธฐ๋ณธ ์žฅ์น˜๋ฅผ ํ™•์ธํ•œ ๋’ค **๋‹ค๋ฅธ ์žฅ์น˜๋กœ ์ž๋™ ์ „ํ™˜**
- ๐Ÿ”Š **๊ธฐ๋ณธ ์žฌ์ƒ ์žฅ์น˜**์™€ **๊ธฐ๋ณธ ํ†ต์‹  ์žฅ์น˜**๋ฅผ ๋™์‹œ์— ์„ค์ •
- ๐Ÿ”” ์ „ํ™˜ ํ›„ ํŠธ๋ ˆ์ด ์•Œ๋ฆผ์œผ๋กœ ์ƒํƒœ ํ‘œ์‹œ
- โšก Stream Deck, AutoHotKey ๋“ฑ **๋‹จ์ถ•ํ‚ค ๋„๊ตฌ์™€ ์—ฐ๋™** ์šฉ์ด

> ๐Ÿ’ก ์žฅ์น˜๊ฐ€ ํ•˜๋‚˜๋ผ๋„ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉด, ์Šคํฌ๋ฆฝํŠธ๋Š” ์ „ํ™˜์„ ์ทจ์†Œํ•˜๊ณ  ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

---

## โœ… ์‚ฌ์šฉ ๋ฐฉ๋ฒ• (Korean)

### 1. ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ
- GitHub์—์„œ **์ดˆ๋ก์ƒ‰ Code ๋ฒ„ํŠผ** ํด๋ฆญ
- **Download ZIP** ์„ ํƒ
- ์••์ถ• ํŒŒ์ผ์„ ํ•ด์ œํ•œ ํ›„, ํด๋”์— ๋‹ค์Œ ํŒŒ์ผ๋“ค์ด ์žˆ๋Š”์ง€ ํ™•์ธ:
- `device.bat`
- `device.vbs`
- `Install_Modules.ps1`

### 2. PowerShell ๋ชจ๋“ˆ ์„ค์น˜ (์ตœ์ดˆ 1ํšŒ๋งŒ)

#### โœ… ์ž๋™ ์„ค์น˜ ๋ฐฉ๋ฒ•
- `Install_Modules.bat` ํŒŒ์ผ์„ **๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ ํด๋ฆญ โ†’ ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰**
- ์•„๋ž˜ ์ž‘์—…์ด ์ž๋™์œผ๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค:
- โœ… ์‹คํ–‰ ์ •์ฑ…์„ `RemoteSigned`๋กœ ์„ค์ •
- ๐ŸŽง `AudioDeviceCmdlets` ๋ชจ๋“ˆ ์„ค์น˜ (์ด๋ฏธ ์„ค์น˜๋œ ๊ฒฝ์šฐ ์ƒ๋žต)
- ๐Ÿ”” `BurntToast` ๋ชจ๋“ˆ ์„ค์น˜ (์ด๋ฏธ ์„ค์น˜๋œ ๊ฒฝ์šฐ ์ƒ๋žต)
- ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค:
```
๐ŸŽ‰ ๋ชจ๋“  ์ค€๋น„ ์™„๋ฃŒ! ์ด์ œ ๋ฐฐ์น˜ ์Šคํฌ๋ฆฝํŠธ์—์„œ ์˜ค๋””์˜ค ์ „ํ™˜๊ณผ ์•Œ๋ฆผ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๐Ÿ‘‹ ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค! ์ฐฝ์„ ๋‹ซ์œผ๋ ค๋ฉด Enter ํ‚ค๋ฅผ ๋ˆ„๋ฅด์„ธ์š”
```
- > โณ **์„ค์น˜ ํ›„ ์ฐฝ์ด ์ž๋™์œผ๋กœ ๋‹ซํžˆ์ง€ ์•Š์œผ๋‹ˆ, Enter ํ‚ค๋ฅผ ๋ˆŒ๋Ÿฌ ์ˆ˜๋™์œผ๋กœ ๋‹ซ์•„์ฃผ์„ธ์š”.**

#### ๐Ÿ›  ์ˆ˜๋™ ์„ค์น˜ ๋ฐฉ๋ฒ•
`Install_Modules.bat` ๋ฅผ ํ†ตํ•ด ๋ชจ๋“ˆ์„ ์„ค์น˜ํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ, ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ PowerShell์— ์ง์ ‘ ๋ณต์‚ฌํ•ด์„œ ๋ถ™์—ฌ๋„ฃ์–ด ์‹คํ–‰ํ•˜์„ธ์š”:

```powershell
# ์‹คํ–‰ ์ •์ฑ…์„ RemoteSigned๋กœ ๋ณ€๊ฒฝ
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force

# AudioDeviceCmdlets ์„ค์น˜
Install-Module -Name AudioDeviceCmdlets -Scope CurrentUser -Force

# BurntToast ์„ค์น˜
Install-Module -Name BurntToast -Scope CurrentUser -Force
```

> โš ๏ธ ๋ชจ๋“ˆ ์„ค์น˜ ์ค‘ 'NuGet ์ œ๊ณต์ž' ๊ด€๋ จ ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜ฌ ๊ฒฝ์šฐ, `Y`๋ฅผ ์ž…๋ ฅํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆŒ๋Ÿฌ ์ง„ํ–‰ํ•˜์„ธ์š”.

---

### 3. NirCmd ๋‹ค์šด๋กœ๋“œ
- ๊ณต์‹ ์‚ฌ์ดํŠธ: [https://www.nirsoft.net/utils/nircmd.html](https://www.nirsoft.net/utils/nircmd.html)
- ํŽ˜์ด์ง€ ํ•˜๋‹จ์—์„œ **โ€œNirCmd 64-bitโ€** ๋‹ค์šด๋กœ๋“œ
- ์••์ถ• ํ•ด์ œ ๊ฒฝ๋กœ: `C:\Program Files\nircmd-x64`
- ํ•ด๋‹น ํด๋” ์•ˆ์— `nircmd.exe` ํŒŒ์ผ์ด ์žˆ๋Š”์ง€ ํ™•์ธ

### 4. ์‹œ์Šคํ…œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๋“ฑ๋ก
- ์‹œ์ž‘ ๋ฉ”๋‰ด์—์„œ **โ€œ์‹œ์Šคํ…œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ํŽธ์ง‘โ€** ๊ฒ€์ƒ‰ ํ›„ ์‹คํ–‰
- **"ํ™˜๊ฒฝ ๋ณ€์ˆ˜(N)..."** ํด๋ฆญ
- **์‹œ์Šคํ…œ ๋ณ€์ˆ˜**์—์„œ `Path` ์„ ํƒ โ†’ **"ํŽธ์ง‘(I)..."** ํด๋ฆญ
- **"์ƒˆ๋กœ ๋งŒ๋“ค๊ธฐ(N)"** ํด๋ฆญ โ†’ `C:\Program Files\nircmd-x64` ์ž…๋ ฅ
- ๋ชจ๋“  ์ฐฝ์„ **"ํ™•์ธ"**์œผ๋กœ ๋‹ซ๊ธฐ

### 5. ์˜ค๋””์˜ค ์žฅ์น˜ ์ด๋ฆ„ ์„ค์ •
- `device.bat` ํŒŒ์ผ์˜ ํ™•์žฅ์ž๋ฅผ `.txt`๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ๋ฉ”๋ชจ์žฅ์—์„œ ์—ด๊ธฐ
- `[์„ค์ •]` ์•„๋ž˜์— `earphone`, `speaker` ํ•ญ๋ชฉ์„ ๋ณธ์ธ์˜ ์žฅ์น˜ ์ด๋ฆ„์œผ๋กœ ์ˆ˜์ •
- ์ €์žฅ ํ›„ ํ™•์žฅ์ž๋ฅผ `.bat`๋กœ ๋‹ค์‹œ ๋ณ€๊ฒฝ

### 6. ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰
- ํด๋” ์•ˆ์˜ `device.vbs` ํŒŒ์ผ์„ ๋”๋ธ” ํด๋ฆญ
- ์‹คํ–‰์ฐฝ ์—†์ด ์กฐ์šฉํžˆ ์˜ค๋””์˜ค ์žฅ์น˜๊ฐ€ ์ „ํ™˜๋จ
- **Stream Deck**, **AutoHotKey** ๋“ฑ์—์„œ ์ด `device.vbs` ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๋„๋ก ์—ฐ๊ฒฐํ•˜๋ฉด ๋” ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ

---

## โœ… How to Use (English)

**SoundDeviceSwitcher** is a batch script for **smartly toggling** between two audio devices on Windows (e.g., headphones and speakers).

Itโ€™s more than just a toggleโ€”this script includes intelligent features:

- โœ… **Only switches if both devices are connected**
- ๐Ÿ” Automatically detects the current default device and switches to the other
- ๐Ÿ”Š Sets both the **Default Playback Device** and **Default Communication Device**
- ๐Ÿ”” Displays a tray notification after switching
- โšก Easily integrates with hotkey tools like Stream Deck or AutoHotKey

> ๐Ÿ’ก If either device is not connected, the script will cancel the operation and show a warning instead of switching.

---

### 1. Download Files
- Click the **green Code button** on GitHub
- Select **Download ZIP**
- Extract the ZIP file and make sure the folder contains:
- `device.bat`
- `device.vbs`
- `Install_Modules.ps1`

### 2. Install PowerShell Modules (one-time setup)

#### โœ… Automatic Method
- Right-click `Install_Modules.bat` and select **Run as Administrator**
- The following will be performed automatically:
- โœ… Set execution policy to `RemoteSigned`
- ๐ŸŽง Install `AudioDeviceCmdlets` module (skipped if already installed)
- ๐Ÿ”” Install `BurntToast` module (skipped if already installed)

#### ๐Ÿ›  Manual Method
If you can't run the script, copy and paste the following into PowerShell manually:

```powershell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force
Install-Module -Name AudioDeviceCmdlets -Scope CurrentUser -Force
Install-Module -Name BurntToast -Scope CurrentUser -Force
```

> โš ๏ธ If prompted to install NuGet provider, type `Y` and press Enter.

---

### 3. Download NirCmd
- Official site: [https://www.nirsoft.net/utils/nircmd.html](https://www.nirsoft.net/utils/nircmd.html)
- Scroll to the bottom and download **โ€œNirCmd 64-bitโ€**
- Extract to: `C:\Program Files\nircmd-x64`
- Ensure `nircmd.exe` is present in that folder

### 4. Add to System Environment Variables
- Open the Start menu and search for **โ€œEdit the system environment variablesโ€**
- Click **โ€œEnvironment Variables...โ€**
- In the **System variables** section, select `Path` โ†’ click **โ€œEdit...โ€**
- Click **โ€œNewโ€** โ†’ add `C:\Program Files\nircmd-x64`
- Click **OK** to close all windows

### 5. Set Your Audio Device Names
- Rename `device.bat` to `.txt` and open it in Notepad
- Under the **[Settings]** section, change the `earphone` and `speaker` entries to match your actual device names
- Save and rename the file extension back to `.bat`

### 6. Run the Script
- Double-click the `device.vbs` file in the folder
- It will switch audio devices silently without opening any command windows
- You can link the `device.vbs` file to tools like **Stream Deck** or **AutoHotKey** for quick access