Last active
December 1, 2024 22:21
-
-
Save quonic/50084546230f933d086997d6dec487a4 to your computer and use it in GitHub Desktop.
Set-StreamDeckSoundboardAudio.ps1: A script that will allow you to change the audio Output for the Soundboard plugin for Stream Deck.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make sure to backup your profile, just in case that Elgato changes the file format. | |
# Scroll down to bottom to see example use case. | |
function Update-Profiles { | |
<# | |
.SYNOPSIS | |
Replaces outputType in all Stream Deck profiles for Elgato's Soundboard plugin. | |
.DESCRIPTION | |
Replaces outputType in all Stream Deck profiles for Elgato's Soundboard plugin. | |
.PARAMETER Replace | |
Changes the "Output" sound device to what you specify. | |
.NOTES | |
General notes | |
#> | |
[CmdletBinding()] | |
param ( | |
[String] | |
$Replace, | |
[String] | |
$ProfileName = "Default Profile" | |
) | |
begin {} | |
process { | |
Get-Profile -Name $ProfileName | ForEach-Object { | |
Get-ChildItem -Path "$($_.Path)\*.json" -Recurse | ForEach-Object { | |
$Path = $_ | |
try { | |
$Content = $_ | Get-Content | ConvertFrom-Json | |
$Buttons = $Content.Controllers | Select-Object -ExpandProperty Actions | |
$Names = $Buttons | Get-Member -MemberType NoteProperty -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*,*" } | Select-Object -Property Name -ExpandProperty Name | |
$Names | ForEach-Object { | |
$Name = $_ | |
$Buttons.$Name.Settings | ForEach-Object { | |
if ($_.outputType) { | |
$_.outputType = $Replace.ToLower() | |
} | |
} | |
} | |
$Content | ConvertTo-Json -Depth 10 -Compress | Set-Content -Path $_ | |
} | |
catch { | |
"Error: $Path" | |
} | |
} | |
} | |
} | |
end {} | |
} | |
function Get-Profile { | |
<# | |
.SYNOPSIS | |
Gets your Stream Deck profiles | |
.DESCRIPTION | |
Gets your Stream Deck profiles, name and path to profile. | |
.PARAMETER Name | |
Filter to a specific profile, or use a wild card to search for more than one. | |
.PARAMETER ProfilePath | |
If your profiles are not in the default path, then specify that here, else don't use. | |
.PARAMETER IncludeAuto | |
Used to include the auto generated profiles, like Wave Link or Volume Control profiles. | |
.EXAMPLE | |
-Name "OBS" | |
.EXAMPLE | |
-Name "Server*" | |
.NOTES | |
General notes | |
#> | |
[CmdletBinding()] | |
param ( | |
[String] | |
$Name, | |
[String] | |
$ProfilePath = "C:\Users\$env:USERNAME\AppData\Roaming\Elgato\StreamDeck\ProfilesV2\", | |
[Switch] | |
$IncludeAuto | |
) | |
begin { | |
$Manifest = "manifest.json" | |
} | |
process { | |
Get-ChildItem -Path $ProfilePath -Directory | ForEach-Object { | |
[PSCustomObject]@{ | |
Path = $_.FullName | |
Json = Get-Item -Path "$ProfilePath\$_\$Manifest" | Get-Content | ConvertFrom-Json | |
} | |
} | Where-Object { | |
# Filters | |
if ($PSBoundParameters.ContainsKey("Name")) { | |
$_.Json.Name -like "$Name" | |
} | |
else { | |
if ($IncludeAuto -and ($_.Json.InstalledByPluginUUID)) { | |
$true | |
} | |
elseif (-not $_.Json.InstalledByPluginUUID) { | |
$true | |
} | |
else { | |
$false | |
} | |
} | |
} | ForEach-Object { | |
[PSCustomObject]@{ | |
Name = $_.Json.Name | |
Path = $_.Path | |
} | |
} | |
} | |
end {} | |
} | |
function Set-AudioOutput { | |
[CmdletBinding()] | |
param ( | |
[String] | |
$ProfileName, | |
[string] | |
$Output | |
) | |
begin {} | |
process { | |
$Device = Get-PnpDevice -Class AudioEndpoint -Status OK | | |
Where-Object { | |
$_.Name -like $Output | |
} | | |
Select-Object -First 1 | |
$Splat = @{ | |
ProfileName = $ProfileName | |
Replace = "$($Device.DeviceID | Split-Path -Leaf)" | |
} | |
Update-Profiles @Splat | |
} | |
end {} | |
} | |
function Get-AudioDevices { | |
param () | |
Get-PnpDevice -Class AudioEndpoint -Status OK -PresentOnly | Select-Object -Property FriendlyName -ExpandProperty FriendlyName | |
} | |
# Example use case: | |
# I want to change all Soundboard audio Output's to "MUSIC (BRIDGE CAST)" | |
# Below will use the functions above to do this. | |
# Use the function Get-AudioDevices to see a list of device names to select from. | |
# Make sure that the device you use makes sense as an Audio Output Device. | |
# Get-AudioDevices | |
# # Change "MUSIC (BRIDGE CAST)" to the device that you wish to use. | |
# $Device_Name = "MUSIC (BRIDGE CAST)" | |
# # Change "Default*" to match the name of the profile you wish the make changes to. | |
# Set-AudioOutput -ProfileName $(Get-Profile -Name "Default*").Name -Output $Device_Name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build a gui for this. Be sure to close Stream Deck before clicking the update button Update! | |
# To run this: | |
# Download this file to your desktop. | |
# Open a powershell: Windows Key + R, type powershell, and click OK. | |
# Type and then press enter: | |
# cd Desktop | |
# Type the name of the file with the .\ in the begining, and then press Enter: | |
# .\UpdateStreamDeckSoundBoardAudioDevice.ps1 | |
# Be sure that Stream Deck is closed!!! | |
# Click on Update Lists. | |
# Select from the left the audio output device you wish to use. | |
# Select from the right the profile you wish to update. | |
# Click on the Update button and wait till the status changes to Updated! | |
# Start Stream Deck. | |
# Check that the soundboards buttons are updated correctly. Repeat as needed for other profiles. | |
# Close the window. | |
#------------------------------------------------------------------------ | |
# Source File Information (DO NOT MODIFY) | |
# Source ID: 2fc15a56-6655-4fcd-a688-c48c37c03cd7 | |
# Source File: Form.psf | |
#------------------------------------------------------------------------ | |
#region File Recovery Data (DO NOT MODIFY) | |
<#RecoveryData: | |
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 | |
Rn6C/y+Qv/4FLNDGPy8HAAA=#> | |
#endregion | |
<# | |
.NOTES | |
-------------------------------------------------------------------------------- | |
Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.195 | |
Generated on: 3/6/2023 8:37 PM | |
Generated by: spyin | |
-------------------------------------------------------------------------------- | |
.DESCRIPTION | |
GUI script generated by PowerShell Studio 2021 | |
#> | |
#---------------------------------------------- | |
#region Application Functions | |
#---------------------------------------------- | |
#endregion Application Functions | |
#---------------------------------------------- | |
# Generated Form Function | |
#---------------------------------------------- | |
function Show-Form_psf { | |
#---------------------------------------------- | |
#region Import the Assemblies | |
#---------------------------------------------- | |
[void][reflection.assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') | |
[void][reflection.assembly]::Load('System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') | |
[void][reflection.assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') | |
#endregion Import Assemblies | |
#---------------------------------------------- | |
#region Generated Form Objects | |
#---------------------------------------------- | |
[System.Windows.Forms.Application]::EnableVisualStyles() | |
$form1 = New-Object 'System.Windows.Forms.Form' | |
$lStatus = New-Object 'System.Windows.Forms.Label' | |
$buttonUpdateProfile = New-Object 'System.Windows.Forms.Button' | |
$buttonUpdateLists = New-Object 'System.Windows.Forms.Button' | |
$cbProfile = New-Object 'System.Windows.Forms.ComboBox' | |
$cbAudioDevice = New-Object 'System.Windows.Forms.ComboBox' | |
$menustripTheme = New-Object 'System.Windows.Forms.MenuStrip' | |
$themeToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem' | |
$darkToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem' | |
$lightToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem' | |
$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState' | |
#endregion Generated Form Objects | |
#---------------------------------------------- | |
# User Generated Script | |
#---------------------------------------------- | |
$form1_Load={ | |
#TODO: Initialize Form Controls here | |
Set-ControlTheme $form1 -Theme Dark | |
} | |
function Get-AudioDevices | |
{ | |
param () | |
Get-PnpDevice -Class AudioEndpoint -Status OK -PresentOnly | Select-Object -Property FriendlyName -ExpandProperty FriendlyName | |
} | |
function Get-Profile | |
{ | |
<# | |
.SYNOPSIS | |
Gets your Stream Deck profiles | |
.DESCRIPTION | |
Gets your Stream Deck profiles, name and path to profile. | |
.PARAMETER Name | |
Filter to a specific profile, or use a wild card to search for more than one. | |
.PARAMETER ProfilePath | |
If your profiles are not in the default path, then specify that here, else don't use. | |
.PARAMETER IncludeAuto | |
Used to include the auto generated profiles, like Wave Link or Volume Control profiles. | |
.EXAMPLE | |
-Name "OBS" | |
.EXAMPLE | |
-Name "Server*" | |
.NOTES | |
General notes | |
#> | |
[CmdletBinding()] | |
param ( | |
[String]$Name, | |
[String]$ProfilePath = "C:\Users\$env:USERNAME\AppData\Roaming\Elgato\StreamDeck\ProfilesV2\", | |
[Switch]$IncludeAuto | |
) | |
begin | |
{ | |
$Manifest = "manifest.json" | |
} | |
process | |
{ | |
Get-ChildItem -Path $ProfilePath -Directory | ForEach-Object { | |
[PSCustomObject]@{ | |
Path = $_.FullName | |
Json = Get-Item -Path "$ProfilePath\$_\$Manifest" | Get-Content | ConvertFrom-Json | |
} | |
} | Where-Object { | |
# Filters | |
if ($PSBoundParameters.ContainsKey("Name")) | |
{ | |
$_.Json.Name -like "$Name" | |
} | |
else | |
{ | |
if ($IncludeAuto -and ($_.Json.InstalledByPluginUUID)) | |
{ | |
$true | |
} | |
elseif (-not $_.Json.InstalledByPluginUUID) | |
{ | |
$true | |
} | |
else | |
{ | |
$false | |
} | |
} | |
} | ForEach-Object { | |
[PSCustomObject]@{ | |
Name = $_.Json.Name | |
Path = $_.Path | |
} | |
} | |
} | |
end { } | |
} | |
function Update-Profiles | |
{ | |
<# | |
.SYNOPSIS | |
Replaces outputType in all Stream Deck profiles for Elgato's Soundboard plugin. | |
.DESCRIPTION | |
Replaces outputType in all Stream Deck profiles for Elgato's Soundboard plugin. | |
.PARAMETER Replace | |
Changes the "Output" sound device to what you specify. | |
.NOTES | |
General notes | |
#> | |
[CmdletBinding()] | |
param ( | |
[String]$Replace, | |
[String]$ProfileName = "Default Profile" | |
) | |
begin { } | |
process | |
{ | |
Get-Profile -Name $ProfileName | ForEach-Object { | |
Get-ChildItem -Path "$($_.Path)\*.json" -Recurse | ForEach-Object { | |
$Path = $_ | |
try | |
{ | |
$Content = $_ | Get-Content | ConvertFrom-Json | |
$Buttons = $Content.Controllers | Select-Object -ExpandProperty Actions | |
$Names = $Buttons | | |
Get-Member -MemberType NoteProperty -ErrorAction SilentlyContinue | | |
Where-Object { $_.Name -like "*,*" } | | |
Select-Object -Property Name -ExpandProperty Name | |
$Names | ForEach-Object { | |
$Name = $_ | |
$Buttons.$Name.Settings | ForEach-Object { | |
if ($_.outputType) | |
{ | |
$_.outputType = $Replace.ToLower() | |
} | |
} | |
} | |
$Content | ConvertTo-Json -Depth 10 -Compress | Set-Content -Path $_ | |
} | |
catch | |
{ | |
"Error: $Path" | |
} | |
} | |
} | |
} | |
end { } | |
} | |
function Set-AudioOutput | |
{ | |
[CmdletBinding()] | |
param ( | |
[String]$ProfileName, | |
[string]$Output | |
) | |
begin { } | |
process | |
{ | |
$Device = Get-PnpDevice -Class AudioEndpoint -Status OK | | |
Where-Object { | |
$_.Name -like $Output | |
} | | |
Select-Object -First 1 | |
$Splat = @{ | |
ProfileName = $ProfileName | |
Replace = "$($Device.DeviceID | Split-Path -Leaf)" | |
} | |
Update-Profiles @Splat | |
} | |
end { } | |
} | |
$darkToolStripMenuItem_Click={ | |
#TODO: Place custom script here | |
Set-ControlTheme -Control $form1 -Theme Dark | |
} | |
$lightToolStripMenuItem_Click={ | |
Set-ControlTheme -Control $form1 -Theme Light | |
} | |
#region Control Theme Helper Function | |
<# | |
.SYNOPSIS | |
Applies a theme to the control and its children. | |
.PARAMETER Control | |
The control to theme. Usually the form itself. | |
.PARAMETER Theme | |
The color theme: | |
Light | |
Dark | |
.PARAMETER CustomColor | |
A hashtable that contains the color values. | |
Keys: | |
WindowColor | |
ContainerColor | |
BackColor | |
ForeColor | |
BorderColor | |
SelectionForeColor | |
SelectionBackColor | |
MenuSelectionColor | |
.EXAMPLE | |
PS C:\> Set-ControlTheme -Control $form1 -Theme Dark | |
.EXAMPLE | |
PS C:\> Set-ControlTheme -Control $form1 -CustomColor @{ WindowColor = 'White'; ContainerBackColor = 'Gray'; BackColor... } | |
.NOTES | |
Created by SAPIEN Technologies, Inc. | |
#> | |
function Set-ControlTheme | |
{ | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNull()] | |
[System.ComponentModel.Component]$Control, | |
[ValidateSet('Light', 'Dark')] | |
[string]$Theme = 'Dark', | |
[System.Collections.Hashtable]$CustomColor | |
) | |
$Font = [System.Drawing.Font]::New('Segoe UI', 9) | |
#Initialize the colors | |
if ($Theme -eq 'Dark') | |
{ | |
$WindowColor = [System.Drawing.Color]::FromArgb(32, 32, 32) | |
$ContainerColor = [System.Drawing.Color]::FromArgb(45, 45, 45) | |
$BackColor = [System.Drawing.Color]::FromArgb(32, 32, 32) | |
$ForeColor = [System.Drawing.Color]::White | |
$BorderColor = [System.Drawing.Color]::DimGray | |
$SelectionBackColor = [System.Drawing.SystemColors]::Highlight | |
$SelectionForeColor = [System.Drawing.Color]::White | |
$MenuSelectionColor = [System.Drawing.Color]::DimGray | |
} | |
else | |
{ | |
$WindowColor = [System.Drawing.Color]::White | |
$ContainerColor = [System.Drawing.Color]::WhiteSmoke | |
$BackColor = [System.Drawing.Color]::Gainsboro | |
$ForeColor = [System.Drawing.Color]::Black | |
$BorderColor = [System.Drawing.Color]::DimGray | |
$SelectionBackColor = [System.Drawing.SystemColors]::Highlight | |
$SelectionForeColor = [System.Drawing.Color]::White | |
$MenuSelectionColor = [System.Drawing.Color]::LightSteelBlue | |
} | |
if ($CustomColor) | |
{ | |
#Check and Validate the custom colors: | |
$Color = $CustomColor.WindowColor -as [System.Drawing.Color] | |
if ($Color) { $WindowColor = $Color } | |
$Color = $CustomColor.ContainerColor -as [System.Drawing.Color] | |
if ($Color) { $ContainerColor = $Color } | |
$Color = $CustomColor.BackColor -as [System.Drawing.Color] | |
if ($Color) { $BackColor = $Color } | |
$Color = $CustomColor.ForeColor -as [System.Drawing.Color] | |
if ($Color) { $ForeColor = $Color } | |
$Color = $CustomColor.BorderColor -as [System.Drawing.Color] | |
if ($Color) { $BorderColor = $Color } | |
$Color = $CustomColor.SelectionBackColor -as [System.Drawing.Color] | |
if ($Color) { $SelectionBackColor = $Color } | |
$Color = $CustomColor.SelectionForeColor -as [System.Drawing.Color] | |
if ($Color) { $SelectionForeColor = $Color } | |
$Color = $CustomColor.MenuSelectionColor -as [System.Drawing.Color] | |
if ($Color) { $MenuSelectionColor = $Color } | |
} | |
#Define the custom renderer for the menus | |
#region Add-Type definition | |
try | |
{ | |
[SAPIENTypes.SAPIENColorTable] | Out-Null | |
} | |
catch | |
{ | |
if ($PSVersionTable.PSVersion.Major -ge 7) | |
{ | |
$Assemblies = 'System.Windows.Forms', 'System.Drawing', 'System.Drawing.Primitives' | |
} | |
else | |
{ | |
$Assemblies = 'System.Windows.Forms', 'System.Drawing' | |
} | |
Add-Type -ReferencedAssemblies $Assemblies -TypeDefinition " | |
using System; | |
using System.Windows.Forms; | |
using System.Drawing; | |
namespace SAPIENTypes | |
{ | |
public class SAPIENColorTable : ProfessionalColorTable | |
{ | |
Color ContainerBackColor; | |
Color BackColor; | |
Color BorderColor; | |
Color SelectBackColor; | |
public SAPIENColorTable(Color containerColor, Color backColor, Color borderColor, Color selectBackColor) | |
{ | |
ContainerBackColor = containerColor; | |
BackColor = backColor; | |
BorderColor = borderColor; | |
SelectBackColor = selectBackColor; | |
} | |
public override Color MenuStripGradientBegin { get { return ContainerBackColor; } } | |
public override Color MenuStripGradientEnd { get { return ContainerBackColor; } } | |
public override Color ToolStripBorder { get { return BorderColor; } } | |
public override Color MenuItemBorder { get { return SelectBackColor; } } | |
public override Color MenuItemSelected { get { return SelectBackColor; } } | |
public override Color SeparatorDark { get { return BorderColor; } } | |
public override Color ToolStripDropDownBackground { get { return BackColor; } } | |
public override Color MenuBorder { get { return BorderColor; } } | |
public override Color MenuItemSelectedGradientBegin { get { return SelectBackColor; } } | |
public override Color MenuItemSelectedGradientEnd { get { return SelectBackColor; } } | |
public override Color MenuItemPressedGradientBegin { get { return ContainerBackColor; } } | |
public override Color MenuItemPressedGradientEnd { get { return ContainerBackColor; } } | |
public override Color MenuItemPressedGradientMiddle { get { return ContainerBackColor; } } | |
public override Color ImageMarginGradientBegin { get { return BackColor; } } | |
public override Color ImageMarginGradientEnd { get { return BackColor; } } | |
public override Color ImageMarginGradientMiddle { get { return BackColor; } } | |
} | |
}" | |
} | |
#endregion | |
$colorTable = New-Object SAPIENTypes.SAPIENColorTable -ArgumentList $ContainerColor, $BackColor, $BorderColor, $MenuSelectionColor | |
$render = New-Object System.Windows.Forms.ToolStripProfessionalRenderer -ArgumentList $colorTable | |
[System.Windows.Forms.ToolStripManager]::Renderer = $render | |
#Set up our processing queue | |
$Queue = New-Object System.Collections.Generic.Queue[System.ComponentModel.Component] | |
$Queue.Enqueue($Control) | |
Add-Type -AssemblyName System.Core | |
#Only process the controls once. | |
$Processed = New-Object System.Collections.Generic.HashSet[System.ComponentModel.Component] | |
#Apply the colors to the controls | |
while ($Queue.Count -gt 0) | |
{ | |
$target = $Queue.Dequeue() | |
#Skip controls we already processed | |
if ($Processed.Contains($target)) { continue } | |
$Processed.Add($target) | |
#Set the text color | |
$target.ForeColor = $ForeColor | |
#region Handle Controls | |
if ($target -is [System.Windows.Forms.Form]) | |
{ | |
#Set Font | |
$target.Font = $Font | |
$target.BackColor = $ContainerColor | |
} | |
elseif ($target -is [System.Windows.Forms.SplitContainer]) | |
{ | |
$target.BackColor = $BorderColor | |
} | |
elseif ($target -is [System.Windows.Forms.PropertyGrid]) | |
{ | |
$target.BackColor = $BorderColor | |
$target.ViewBackColor = $BackColor | |
$target.ViewForeColor = $ForeColor | |
$target.ViewBorderColor = $BorderColor | |
$target.CategoryForeColor = $ForeColor | |
$target.CategorySplitterColor = $ContainerColor | |
$target.HelpBackColor = $BackColor | |
$target.HelpForeColor = $ForeColor | |
$target.HelpBorderColor = $BorderColor | |
$target.CommandsBackColor = $BackColor | |
$target.CommandsBorderColor = $BorderColor | |
$target.CommandsForeColor = $ForeColor | |
$target.LineColor = $ContainerColor | |
} | |
elseif ($target -is [System.Windows.Forms.ContainerControl] -or | |
$target -is [System.Windows.Forms.Panel]) | |
{ | |
#Set the BackColor for the container | |
$target.BackColor = $ContainerColor | |
} | |
elseif ($target -is [System.Windows.Forms.GroupBox]) | |
{ | |
$target.FlatStyle = 'Flat' | |
} | |
elseif ($target -is [System.Windows.Forms.Button]) | |
{ | |
$target.FlatStyle = 'Flat' | |
$target.FlatAppearance.BorderColor = $BorderColor | |
$target.BackColor = $BackColor | |
} | |
elseif ($target -is [System.Windows.Forms.CheckBox] -or | |
$target -is [System.Windows.Forms.RadioButton] -or | |
$target -is [System.Windows.Forms.Label]) | |
{ | |
#$target.FlatStyle = 'Flat' | |
} | |
elseif ($target -is [System.Windows.Forms.ComboBox]) | |
{ | |
$target.BackColor = $BackColor | |
$target.FlatStyle = 'Flat' | |
} | |
elseif ($target -is [System.Windows.Forms.TextBox]) | |
{ | |
$target.BorderStyle = 'FixedSingle' | |
$target.BackColor = $BackColor | |
} | |
elseif ($target -is [System.Windows.Forms.DataGridView]) | |
{ | |
$target.GridColor = $BorderColor | |
$target.BackgroundColor = $ContainerColor | |
$target.DefaultCellStyle.BackColor = $WindowColor | |
$target.DefaultCellStyle.SelectionBackColor = $SelectionBackColor | |
$target.DefaultCellStyle.SelectionForeColor = $SelectionForeColor | |
$target.ColumnHeadersDefaultCellStyle.BackColor = $ContainerColor | |
$target.ColumnHeadersDefaultCellStyle.ForeColor = $ForeColor | |
$target.EnableHeadersVisualStyles = $false | |
$target.ColumnHeadersBorderStyle = 'Single' | |
$target.RowHeadersBorderStyle = 'Single' | |
$target.RowHeadersDefaultCellStyle.BackColor = $ContainerColor | |
$target.RowHeadersDefaultCellStyle.ForeColor = $ForeColor | |
} | |
elseif ($PSVersionTable.PSVersion.Major -le 5 -and $target -is [System.Windows.Forms.DataGrid]) | |
{ | |
$target.CaptionBackColor = $WindowColor | |
$target.CaptionForeColor = $ForeColor | |
$target.BackgroundColor = $ContainerColor | |
$target.BackColor = $WindowColor | |
$target.ForeColor = $ForeColor | |
$target.HeaderBackColor = $ContainerColor | |
$target.HeaderForeColor = $ForeColor | |
$target.FlatMode = $true | |
$target.BorderStyle = 'FixedSingle' | |
$target.GridLineColor = $BorderColor | |
$target.AlternatingBackColor = $ContainerColor | |
$target.SelectionBackColor = $SelectionBackColor | |
$target.SelectionForeColor = $SelectionForeColor | |
} | |
elseif ($target -is [System.Windows.Forms.ToolStrip]) | |
{ | |
$target.BackColor = $BackColor | |
$target.Renderer = $render | |
foreach ($item in $target.Items) | |
{ | |
$Queue.Enqueue($item) | |
} | |
} | |
elseif ($target -is [System.Windows.Forms.ToolStripMenuItem] -or | |
$target -is [System.Windows.Forms.ToolStripDropDown] -or | |
$target -is [System.Windows.Forms.ToolStripDropDownItem]) | |
{ | |
$target.BackColor = $BackColor | |
foreach ($item in $target.DropDownItems) | |
{ | |
$Queue.Enqueue($item) | |
} | |
} | |
elseif ($target -is [System.Windows.Forms.ListBox] -or | |
$target -is [System.Windows.Forms.ListView] -or | |
$target -is [System.Windows.Forms.TreeView]) | |
{ | |
$target.BackColor = $WindowColor | |
} | |
else | |
{ | |
$target.BackColor = $BackColor | |
} | |
#endregion | |
if ($target -is [System.Windows.Forms.Control]) | |
{ | |
#Queue all the child controls | |
foreach ($child in $target.Controls) | |
{ | |
$Queue.Enqueue($child) | |
} | |
} | |
} | |
} | |
#endregion | |
#region Control Helper Functions | |
function Update-ComboBox | |
{ | |
<# | |
.SYNOPSIS | |
This functions helps you load items into a ComboBox. | |
.DESCRIPTION | |
Use this function to dynamically load items into the ComboBox control. | |
.PARAMETER ComboBox | |
The ComboBox control you want to add items to. | |
.PARAMETER Items | |
The object or objects you wish to load into the ComboBox's Items collection. | |
.PARAMETER DisplayMember | |
Indicates the property to display for the items in this control. | |
.PARAMETER ValueMember | |
Indicates the property to use for the value of the control. | |
.PARAMETER Append | |
Adds the item(s) to the ComboBox without clearing the Items collection. | |
.EXAMPLE | |
Update-ComboBox $combobox1 "Red", "White", "Blue" | |
.EXAMPLE | |
Update-ComboBox $combobox1 "Red" -Append | |
Update-ComboBox $combobox1 "White" -Append | |
Update-ComboBox $combobox1 "Blue" -Append | |
.EXAMPLE | |
Update-ComboBox $combobox1 (Get-Process) "ProcessName" | |
.NOTES | |
Additional information about the function. | |
#> | |
param | |
( | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNull()] | |
[System.Windows.Forms.ComboBox] | |
$ComboBox, | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNull()] | |
$Items, | |
[Parameter(Mandatory = $false)] | |
[string]$DisplayMember, | |
[Parameter(Mandatory = $false)] | |
[string]$ValueMember, | |
[switch] | |
$Append | |
) | |
if (-not $Append) | |
{ | |
$ComboBox.Items.Clear() | |
} | |
if ($Items -is [Object[]]) | |
{ | |
$ComboBox.Items.AddRange($Items) | |
} | |
elseif ($Items -is [System.Collections.IEnumerable]) | |
{ | |
$ComboBox.BeginUpdate() | |
foreach ($obj in $Items) | |
{ | |
$ComboBox.Items.Add($obj) | |
} | |
$ComboBox.EndUpdate() | |
} | |
else | |
{ | |
$ComboBox.Items.Add($Items) | |
} | |
if ($DisplayMember) | |
{ | |
$ComboBox.DisplayMember = $DisplayMember | |
} | |
if ($ValueMember) | |
{ | |
$ComboBox.ValueMember = $ValueMember | |
} | |
} | |
#endregion | |
$buttonUpdateLists_Click={ | |
Update-ComboBox -ComboBox $cbAudioDevice -Items $(Get-AudioDevices) | |
Update-ComboBox -ComboBox $cbProfile -Items $(Get-Profile).Name | |
} | |
$buttonUpdateProfile_Click={ | |
if ( | |
( | |
$cbAudioDevice.SelectedItem.ToString() -in $(Get-AudioDevices) -and | |
-not [string]::IsNullOrEmpty($cbAudioDevice.SelectedItem.ToString()) -and | |
-not [string]::IsNullOrWhiteSpace($cbAudioDevice.SelectedItem.ToString()) | |
) -and | |
( | |
$cbProfile.SelectedItem.ToString() -in $(Get-Profile).Name -and | |
-not [string]::IsNullOrEmpty($cbProfile.SelectedItem.ToString()) -and | |
-not [string]::IsNullOrWhiteSpace($cbProfile.SelectedItem.ToString()) | |
) | |
) | |
{ | |
$lStatus.Text = "Working..." | |
Set-AudioOutput -ProfileName $cbProfile.SelectedItem.ToString() -Output $cbAudioDevice.SelectedItem.ToString() | |
$lStatus.Text = "Updated!" | |
} | |
} | |
# --End User Generated Script-- | |
#---------------------------------------------- | |
#region Generated Events | |
#---------------------------------------------- | |
$Form_StateCorrection_Load= | |
{ | |
#Correct the initial state of the form to prevent the .Net maximized form issue | |
$form1.WindowState = $InitialFormWindowState | |
} | |
$Form_Cleanup_FormClosed= | |
{ | |
#Remove all event handlers from the controls | |
try | |
{ | |
$buttonUpdateProfile.remove_Click($buttonUpdateProfile_Click) | |
$buttonUpdateLists.remove_Click($buttonUpdateLists_Click) | |
$form1.remove_Load($form1_Load) | |
$darkToolStripMenuItem.remove_Click($darkToolStripMenuItem_Click) | |
$lightToolStripMenuItem.remove_Click($lightToolStripMenuItem_Click) | |
$form1.remove_Load($Form_StateCorrection_Load) | |
$form1.remove_FormClosed($Form_Cleanup_FormClosed) | |
} | |
catch { Out-Null <# Prevent PSScriptAnalyzer warning #> } | |
} | |
#endregion Generated Events | |
#---------------------------------------------- | |
#region Generated Form Code | |
#---------------------------------------------- | |
$form1.SuspendLayout() | |
$menustripTheme.SuspendLayout() | |
# | |
# form1 | |
# | |
$form1.Controls.Add($lStatus) | |
$form1.Controls.Add($buttonUpdateProfile) | |
$form1.Controls.Add($buttonUpdateLists) | |
$form1.Controls.Add($cbProfile) | |
$form1.Controls.Add($cbAudioDevice) | |
$form1.Controls.Add($menustripTheme) | |
$form1.AutoScaleDimensions = New-Object System.Drawing.SizeF(6, 13) | |
$form1.AutoScaleMode = 'Font' | |
$form1.ClientSize = New-Object System.Drawing.Size(654, 159) | |
$form1.Name = 'form1' | |
$form1.StartPosition = 'CenterScreen' | |
$form1.Text = 'Form' | |
$form1.add_Load($form1_Load) | |
# | |
# lStatus | |
# | |
$lStatus.AutoSize = $True | |
$lStatus.Location = New-Object System.Drawing.Point(297, 137) | |
$lStatus.Name = 'lStatus' | |
$lStatus.Size = New-Object System.Drawing.Size(123, 13) | |
$lStatus.TabIndex = 19 | |
$lStatus.Text = 'Close Stream Deck First!' | |
# | |
# buttonUpdateProfile | |
# | |
$buttonUpdateProfile.Location = New-Object System.Drawing.Point(297, 104) | |
$buttonUpdateProfile.Name = 'buttonUpdateProfile' | |
$buttonUpdateProfile.Size = New-Object System.Drawing.Size(75, 23) | |
$buttonUpdateProfile.TabIndex = 18 | |
$buttonUpdateProfile.Text = 'Update Profile' | |
$buttonUpdateProfile.UseVisualStyleBackColor = $True | |
$buttonUpdateProfile.add_Click($buttonUpdateProfile_Click) | |
# | |
# buttonUpdateLists | |
# | |
$buttonUpdateLists.Location = New-Object System.Drawing.Point(297, 61) | |
$buttonUpdateLists.Name = 'buttonUpdateLists' | |
$buttonUpdateLists.Size = New-Object System.Drawing.Size(75, 23) | |
$buttonUpdateLists.TabIndex = 17 | |
$buttonUpdateLists.Text = 'Update Lists' | |
$buttonUpdateLists.UseVisualStyleBackColor = $True | |
$buttonUpdateLists.add_Click($buttonUpdateLists_Click) | |
# | |
# cbProfile | |
# | |
$cbProfile.FormattingEnabled = $True | |
$cbProfile.Location = New-Object System.Drawing.Point(400, 63) | |
$cbProfile.Name = 'cbProfile' | |
$cbProfile.Size = New-Object System.Drawing.Size(242, 21) | |
$cbProfile.TabIndex = 16 | |
# | |
# cbAudioDevice | |
# | |
$cbAudioDevice.FormattingEnabled = $True | |
$cbAudioDevice.Location = New-Object System.Drawing.Point(12, 63) | |
$cbAudioDevice.Name = 'cbAudioDevice' | |
$cbAudioDevice.Size = New-Object System.Drawing.Size(261, 21) | |
$cbAudioDevice.TabIndex = 15 | |
# | |
# menustripTheme | |
# | |
$menustripTheme.ImageScalingSize = New-Object System.Drawing.Size(20, 20) | |
[void]$menustripTheme.Items.Add($themeToolStripMenuItem) | |
$menustripTheme.Location = New-Object System.Drawing.Point(0, 0) | |
$menustripTheme.Name = 'menustripTheme' | |
$menustripTheme.Padding = '5, 2, 0, 2' | |
$menustripTheme.ShowItemToolTips = $True | |
$menustripTheme.Size = New-Object System.Drawing.Size(654, 28) | |
$menustripTheme.TabIndex = 14 | |
$menustripTheme.Text = 'menustrip1' | |
# | |
# themeToolStripMenuItem | |
# | |
$themeToolStripMenuItem.Alignment = 'Right' | |
[void]$themeToolStripMenuItem.DropDownItems.Add($darkToolStripMenuItem) | |
[void]$themeToolStripMenuItem.DropDownItems.Add($lightToolStripMenuItem) | |
#region Binary Data | |
$Formatter_binaryFomatter = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter | |
$System_IO_MemoryStream = New-Object System.IO.MemoryStream (,[byte[]][System.Convert]::FromBase64String(' | |
AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj00LjAuMC4wLCBD | |
dWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0 | |
ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAALAEAAAKJUE5HDQoaCgAA | |
AA1JSERSAAAAEAAAABAIBgAAAB/z/2EAAAAEZ0FNQQAAsY8L/GEFAAAACXBIWXMAAA68AAAOvAGV | |
vHJJAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4xLjVkR1hSAAAAqklEQVQ4T2P4//8/RRhC | |
oAH7qm0T7So2/wDi/1D8zb5qaz9UGg4wDLCr3OqKpAkXtoMqRzUAqNkZi2IceIs1pgFYFeLGKAY4 | |
1OzqxaYIHwaGUwfcACDnOzZFBPA7ZAOwKSCIqWoAZV5wqN3dj0UBXmxfvR0RiBRHIwgATSQ+IVVu | |
xUxIIECUIZVbbaHKMQ2AAYfaXROBAfsDFDtQ/B2U2KDScAA3gHz8nwEAonU00JrpvTMAAAAASUVO | |
RK5CYIIL')) | |
#endregion | |
$themeToolStripMenuItem.Image = $Formatter_binaryFomatter.Deserialize($System_IO_MemoryStream) | |
$Formatter_binaryFomatter = $null | |
$System_IO_MemoryStream = $null | |
$themeToolStripMenuItem.Name = 'themeToolStripMenuItem' | |
$themeToolStripMenuItem.Size = New-Object System.Drawing.Size(32, 24) | |
$themeToolStripMenuItem.ToolTipText = 'Theme' | |
# | |
# darkToolStripMenuItem | |
# | |
$darkToolStripMenuItem.Name = 'darkToolStripMenuItem' | |
$darkToolStripMenuItem.Size = New-Object System.Drawing.Size(104, 22) | |
$darkToolStripMenuItem.Text = 'Dark' | |
$darkToolStripMenuItem.add_Click($darkToolStripMenuItem_Click) | |
# | |
# lightToolStripMenuItem | |
# | |
$lightToolStripMenuItem.Name = 'lightToolStripMenuItem' | |
$lightToolStripMenuItem.Size = New-Object System.Drawing.Size(104, 22) | |
$lightToolStripMenuItem.Text = 'Light' | |
$lightToolStripMenuItem.add_Click($lightToolStripMenuItem_Click) | |
$menustripTheme.ResumeLayout() | |
$form1.ResumeLayout() | |
#endregion Generated Form Code | |
#---------------------------------------------- | |
#Save the initial state of the form | |
$InitialFormWindowState = $form1.WindowState | |
#Init the OnLoad event to correct the initial state of the form | |
$form1.add_Load($Form_StateCorrection_Load) | |
#Clean up the control events | |
$form1.add_FormClosed($Form_Cleanup_FormClosed) | |
#Show the Form | |
return $form1.ShowDialog() | |
} #End Function | |
#Call the form | |
Show-Form_psf | Out-Null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment