Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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.

Notifications You must be signed in to change notification settings

jaries23/SoundDeviceSwitcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎧 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에 직접 복사해서 붙여넣어 실행하세요:

# 실행 정책을 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
  • 페이지 하단에서 “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:

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

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

About

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.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published