-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChangeOutputDevice.ps1
59 lines (49 loc) · 3.41 KB
/
ChangeOutputDevice.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<#
.DESCRIPTION
https://www.powershellgallery.com/packages/AudioDeviceCmdlets/3.1.0.2
https://github.com/frgnca/AudioDeviceCmdlets
.EXAMPLE
Get-AudioDevice -List | Where-Object Type -like "Playback" | Where-Object name -like "*Realtek*"
Set-AudioDevice -ID "{0.0.0.00000000}.{4229d439-1b7d-4deb-894e-544bb0fa40e1}" # speakers
Set-AudioDevice -ID "{0.0.0.00000000}.{69274eea-2c89-451d-813a-c9407258be99}" # headphones
Get-AudioDevice -List | Where-Object Type -like "Recording" | Where-Object Name -Like "*V8*" | Set-AudioDevice # set v8 mixer as default recording device
Get-AudioDevice -List | Where-Object Type -Like "Playback" | Where-Object Name -Like "*speakers*" | Set-AudioDevice # set speakers as default playback device
#>
function WindowsNotificationBalloon($text) {
# windows 10 notification balloon
Add-Type -AssemblyName System.Windows.Forms
$global:BalloonNotification = New-Object System.Windows.Forms.NotifyIcon
$path = (Get-Process -id $pid).Path
$BalloonNotification.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$BalloonNotification.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info
$BalloonNotification.BalloonTipText = "${text}"
$BalloonNotification.BalloonTipTitle = "Change Output Device"
$BalloonNotification.Visible = $true
$BalloonNotification.ShowBalloonTip(5000)
}
$HeadphonesDeviceName = "Headphones (CDS.KT USB Audio)"
$SpeakersDeviceName = "Output Monitor (2- AMD High Definition Audio Device)"
$SoundcardDeviceName = "Output Mixer (V8)"
# if headphones is the default output then change it to speakers
if (Get-AudioDevice -PlaybackCommunication | Where-Object Type -Like "Playback" | Where-Object Name -Like "$HeadphonesDeviceName") {
Write-Host "Change default audio device to Speakers."
Get-AudioDevice -List | Where-Object Type -Like "Playback" | Where-Object Name -Like "$SpeakersDeviceName" | Set-AudioDevice
WindowsNotificationBalloon "Change default audio device to Speakers."
} # if speakers is default audio then change it to headphones
elseif (Get-AudioDevice -PlaybackCommunication | Where-Object Type -Like "Playback" | Where-Object Name -Like "$SpeakersDeviceName") {
# if there's no headphone device output then change it to soundcard output
if (!(Get-AudioDevice -List | Where-Object Type -Like "Playback" | Where-Object Name -Like "$HeadphonesDeviceName")) {
Write-Host "Change default audio device to Output Mixer."
Get-AudioDevice -List | Where-Object Type -Like "Playback" | Where-Object Name -Like "$SoundcardDeviceName" | Set-AudioDevice
WindowsNotificationBalloon "Change default audio device to Output Mixer."
return
}
Write-Host "Change default audio device to Headphones."
Get-AudioDevice -List | Where-Object Type -Like "Playback" | Where-Object Name -Like "$HeadphonesDeviceName" | Set-AudioDevice
WindowsNotificationBalloon "Change default audio device to Headphones."
} # if soundcard is default audio then change it to speakers
elseif (Get-AudioDevice -PlaybackCommunication | Where-Object Type -Like "Playback" | Where-Object Name -Like "$SoundcardDeviceName") {
Write-Host "Change default audio device to Speakers."
Get-AudioDevice -List | Where-Object Type -Like "Playback" | Where-Object Name -Like "$SpeakersDeviceName" | Set-AudioDevice
WindowsNotificationBalloon "Change default audio device to Speakers."
}