Scripts/Set-BPAKeyboardCondition.ps1
function Set-BPAKeyboardCondition { <# .SYNOPSIS Sets properties of an AutoMate BPA keyboard condition. .DESCRIPTION Set-BPAKeyboardCondition modifies an existing keyboard condition. .PARAMETER InputObject The condition to modify. .PARAMETER Hotkey The hotkey to trigger the condition. .PARAMETER HotkeyPassthrough Allow hotkey to continue to the application. .PARAMETER Text The text to trigger the condition. .PARAMETER EraseText Erase text afterwards. .PARAMETER Process Only run when the specified process is active. .PARAMETER ProcessFocused The process window must be focused. .PARAMETER Notes The new notes to set on the object. .NOTES Author(s): : David Seibel Contributor(s) : Date Created : 02/05/2018 Date Modified : 02/08/2018 .LINK https://github.com/davidseibel/PoshBPA #> [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium")] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] $InputObject, [Parameter(ParameterSetName="Hotkey")] [string]$Hotkey, [Parameter(ParameterSetName="Hotkey")] [switch]$HotkeyPassthrough, [Parameter(ParameterSetName="Text")] [string]$Text, [Parameter(ParameterSetName="Text")] [switch]$EraseText, [string]$Process, [switch]$ProcessFocused, [string]$Notes ) PROCESS { foreach ($obj in $InputObject) { if ($obj.TypeName -eq "Condition" -and $obj.TriggerType -eq [BPATriggerType]::Keyboard.value__) { $update = Get-BPACondition -ID $obj.ID -BPAServer $obj.BPAServer $shouldUpdate = $false switch ($PSCmdlet.ParameterSetName) { "Hotkey" { $update.KeyType = [BPAKeyboardConditionKeyType]::Hotkey.value__ if (($PSBoundParameters.ContainsKey("Hotkey")) -and ($update.Keys -ne $Hotkey)) { $update.Keys = $Hotkey $shouldUpdate = $true } if (($PSBoundParameters.ContainsKey("HotkeyPassthrough")) -and ($update.PassThrough -ne $HotkeyPassthrough.ToBool())) { $update.PassThrough = $HotkeyPassthrough.ToBool() $shouldUpdate = $true } } "Text" { $update.KeyType = [BPAKeyboardConditionKeyType]::Text.value__ if (($PSBoundParameters.ContainsKey("Text")) -and ($update.Keys -ne $Text)) { $update.Keys = $Text $shouldUpdate = $true } if (($PSBoundParameters.ContainsKey("EraseText")) -and ($update.EraseText -ne $EraseText.ToBool())) { $update.EraseText = $EraseText.ToBool() $shouldUpdate = $true } } } if (($PSBoundParameters.ContainsKey("Process")) -and ($update.Process -ne $Process)) { $update.Process = $Process $shouldUpdate = $true } if (($PSBoundParameters.ContainsKey("ProcessFocused")) -and ($update.Foreground -ne $ProcessFocused.ToBool())) { $update.Foreground = $ProcessFocused.ToBool() $shouldUpdate = $true } if (($PSBoundParameters.ContainsKey("Notes")) -and ($update.Notes -ne $Notes)) { $update.Notes = $Notes $shouldUpdate = $true } if ($shouldUpdate) { $update | Set-BPAObject } else { Write-Verbose "$($obj.TypeName) '$($obj.Name)' already contains the specified values." } } else { Write-Error -Message "Unsupported input type '$($obj.TypeName)' and trigger type '$($obj.TriggerType -as [BPATriggerType])' encountered!" -TargetObject $obj } } } } |