Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions EXAMPLE/BootSwitchAudioDevice.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
start powershell -file .\SwitchAudioDevice.ps1
exit
27 changes: 27 additions & 0 deletions EXAMPLE/PlaySound.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<#
Copyright (c) 2016-2022 Francois Gendron <fg@frgn.ca>
MIT License

This file is a script that toggles between two playback audio devices using
AudioDeviceCmdlets then plays a sound for confirmation
AudioDeviceCmdlets is a suite of PowerShell Cmdlets to control audio devices
on Windows
https://github.com/frgnca/AudioDeviceCmdlets
#>

# This script toggles between two playback audio devices then plays a sound for confirmation
# The devices are defined by their ID (Get-AudioDevice -List)

# Bonus: Run this PowerShell script from a VBScript to avoid visible window
# Toggle-AudioDevice.vbs
<#
command = "powershell.exe -nologo -command C:\Path\To\PlaySound.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0
#>

# Play sound
$Sound = new-Object System.Media.SoundPlayer
$Sound.SoundLocation = "c:\WINDOWS\Media\Windows Background.wav"
$Sound.Play()
Start-Sleep -s 3
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ https://github.com/frgnca/AudioDeviceCmdlets
# Bonus: Run this PowerShell script from a VBScript to avoid visible window
# Toggle-AudioDevice.vbs
<#
command = "powershell.exe -nologo -command C:\Path\To\Toggle-AudioDevice.ps1"
command = "powershell.exe -nologo -command C:\Path\To\SwitchAudioDevice.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0
#>
Expand All @@ -28,9 +28,3 @@ $AudioDevice_B = "{0.0.0.00000000}.{c4aadd95-74c7-4b3b-9508-b0ef36ff71ba}"
$DefaultPlayback = Get-AudioDevice -Playback
If ($DefaultPlayback.ID -eq $AudioDevice_A) {Set-AudioDevice -ID $AudioDevice_B | Out-Null}
Else {Set-AudioDevice -ID $AudioDevice_A | Out-Null}

# Play sound
$Sound = new-Object System.Media.SoundPlayer
$Sound.SoundLocation = "c:\WINDOWS\Media\Windows Background.wav"
$Sound.Play()
Start-Sleep -s 3