Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divide example code and add a .bat file to boot .ps1 file #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 <[email protected]>
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