Public/Set/Set-ISEColor.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
function Set-ISEColor {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions','')]
    [cmdletbinding()]
    Param(
        [Parameter(Mandatory=$True,ParameterSetName='Cooler',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [switch]$Cooler,

        [Parameter(Mandatory=$True,ParameterSetName='Warmer',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [switch]$Warmer,

        [Parameter(Mandatory=$True,ParameterSetName='Greener',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [switch]$Greener,

        [Parameter(Mandatory=$True,ParameterSetName='Darker',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [switch]$Darker,

        [Parameter(Mandatory=$True,ParameterSetName='Lighter',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [switch]$Lighter,

        [Parameter(ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [int]$Degree = 20
    )

    Begin{$XmlTheme = Get-CurrentISETheme; $Subtract = $Degree / 2}

    Process {
        $NewColors = @()

        If ($Cooler) {
            ForEach ($Attribute in $XmlTheme) {
                # Rewrite new color values to NewColors
                If ($Attribute.Class -ne 'Other') {
                    $var_A = $Attribute.A
                    If (($Attribute.R - $Subtract) -ge 0) {$var_R = $Attribute.R - $Subtract} Else {$var_R = $Attribute.R}
                    $var_G = $Attribute.G
                    If (($Attribute.B + $Degree) -lt 255) {$var_B = $Attribute.B + $Degree} Else {$var_B = $Attribute.B}
                        
                    #-Convert ARGB values to Hex
                    $Hex = Convert-ARGBToHex "$var_A,$var_R,$var_G,$var_B"

                    #-Create new xml object and add it the the xml object array
                    $xmlObj = New-Object -Type PSObject
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Class –Value $Attribute.Class
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Attribute –Value $Attribute.Attribute
                    $xmlObj | Add-Member -MemberType NoteProperty -Name A –Value $var_A
                    $xmlObj | Add-Member -MemberType NoteProperty -Name R –Value $var_R
                    $xmlObj | Add-Member -MemberType NoteProperty -Name G –Value $var_G
                    $xmlObj | Add-Member -MemberType NoteProperty -Name B –Value $var_B
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Hex –Value $Hex
                    $NewColors += $xmlObj
                        
                }
            }
        }

        If ($Warmer) {
            ForEach ($Attribute in $XmlTheme) {
                # Write Base Colors Values
                If ($Attribute.Class -ne 'Other') {
                    $var_A = $Attribute.A 
                    If (($Attribute.R + $Degree) -lt 255) {$var_R = $Attribute.R + $Degree} Else {$var_R = $Attribute.R}
                    $var_G = $Attribute.G
                    If (($Attribute.B - $Subtract) -ge 0) {$var_B = $Attribute.B - $Subtract} Else {$var_B = $Attribute.B}
                        
                    #-Convert ARGB values to Hex
                    $Hex = Convert-ARGBToHex "$var_A,$var_R,$var_G,$var_B"
                        
                    #-Create new xml object and add it the the xml object array
                    $xmlObj = New-Object -Type PSObject
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Class –Value $Attribute.Class
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Attribute –Value $Attribute.Attribute
                    $xmlObj | Add-Member -MemberType NoteProperty -Name A –Value $var_A
                    $xmlObj | Add-Member -MemberType NoteProperty -Name R –Value $var_R
                    $xmlObj | Add-Member -MemberType NoteProperty -Name G –Value $var_G
                    $xmlObj | Add-Member -MemberType NoteProperty -Name B –Value $var_B
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Hex –Value $Hex
                    $NewColors += $xmlObj                              
                }
            } 
        }

        If ($Greener) {
            ForEach ($Attribute in $XmlTheme) {
                # Write Base Colors Values
                If ($Attribute.Class -ne 'Other') {
                    $var_A = $Attribute.A
                    If (($Attribute.R - $Subtract) -ge 0) {$var_R = $Attribute.R - ($Subtract / 2)} Else {$var_R = $Attribute.R}
                    If (($Attribute.G + $Degree) -lt 255) {$var_G = $Attribute.G + $Degree} Else {$var_G = $Attribute.G}
                    If (($Attribute.B - $Subtract) -ge 0) {$var_B = $Attribute.B - ($Subtract / 2)} Else {$var_B = $Attribute.B}
                        
                    #-Convert ARGB values to Hex
                    $Hex = Convert-ARGBToHex "$var_A,$var_R,$var_G,$var_B"
                        
                    #-Create new xml object and add it the the xml object array
                    $xmlObj = New-Object -Type PSObject
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Class –Value $Attribute.Class
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Attribute –Value $Attribute.Attribute
                    $xmlObj | Add-Member -MemberType NoteProperty -Name A –Value $var_A
                    $xmlObj | Add-Member -MemberType NoteProperty -Name R –Value $var_R
                    $xmlObj | Add-Member -MemberType NoteProperty -Name G –Value $var_G
                    $xmlObj | Add-Member -MemberType NoteProperty -Name B –Value $var_B
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Hex –Value $Hex
                    $NewColors += $xmlObj                              
                }
            } 
        }

        If ($Darker) {
            ForEach ($Attribute in $XmlTheme) {
                # Write Base Colors Values
                If ($Attribute.Class -ne 'Other') {
                    $var_A = $Attribute.A
                    If (($Attribute.R - $Degree) -ige 0) {$var_R = $Attribute.R - $Degree} Else {$var_R = $Attribute.R}
                    If (($Attribute.G - $Degree) -ige 0) {$var_G = $Attribute.G - $Degree} Else {$var_G = $Attribute.G}
                    If (($Attribute.B - $Degree) -ige 0) {$var_B = $Attribute.B - $Degree} Else {$var_B = $Attribute.B}
                        
                    #-Convert ARGB values to Hex
                    $Hex = Convert-ARGBToHex "$var_A,$var_R,$var_G,$var_B"
                        
                    #-Create new xml object and add it the the xml object array
                    $xmlObj = New-Object -Type PSObject
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Class –Value $Attribute.Class
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Attribute –Value $Attribute.Attribute
                    $xmlObj | Add-Member -MemberType NoteProperty -Name A –Value $var_A
                    $xmlObj | Add-Member -MemberType NoteProperty -Name R –Value $var_R
                    $xmlObj | Add-Member -MemberType NoteProperty -Name G –Value $var_G
                    $xmlObj | Add-Member -MemberType NoteProperty -Name B –Value $var_B
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Hex –Value $Hex
                    $NewColors += $xmlObj                              
                }
            } 
        }

        If ($Lighter) {
            ForEach ($Attribute in $XmlTheme) {
                # Write Base Colors Values
                If ($Attribute.Class -ne 'Other') {
                    $var_A = $Attribute.A
                    If (($Attribute.R + $Degree) -lt 255) {$var_R = $Attribute.R + $Degree} Else {$var_R = $Attribute.R}
                    If (($Attribute.G + $Degree) -lt 255) {$var_G = $Attribute.G + $Degree} Else {$var_G = $Attribute.G}
                    If (($Attribute.B + $Degree) -lt 255) {$var_B = $Attribute.B + $Degree} Else {$var_B = $Attribute.B}
                        
                    #-Convert ARGB values to Hex
                    $Hex = Convert-ARGBToHex "$var_A,$var_R,$var_G,$var_B"
                        
                    #-Create new xml object and add it the the xml object array
                    $xmlObj = New-Object -Type PSObject
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Class –Value $Attribute.Class
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Attribute –Value $Attribute.Attribute
                    $xmlObj | Add-Member -MemberType NoteProperty -Name A –Value $var_A
                    $xmlObj | Add-Member -MemberType NoteProperty -Name R –Value $var_R
                    $xmlObj | Add-Member -MemberType NoteProperty -Name G –Value $var_G
                    $xmlObj | Add-Member -MemberType NoteProperty -Name B –Value $var_B
                    $xmlObj | Add-Member -MemberType NoteProperty -Name Hex –Value $Hex
                    $NewColors += $xmlObj                              
                }
            } 
        }


    }

    End {Set-ISETheme -ThemeObject $NewColors}
    <#
        .SYNOPSIS
      Changes ISE Theme colors according to switch
 
     .DESCRIPTION
      Changes ISE Theme colors according to switch. It does this
            by adding or subtracting values in the ARGB table
 
     .PARAMETER Cooler
      Increases blue color values and decreases red by half
 
     .PARAMETER Warmer
      Increases red color values and decreases blue by half
 
     .PARAMETER Greener
      Increases green color values and decreases blue and red by a quarter
 
     .PARAMETER Darker
      Decreases all color values
 
     .PARAMETER Lighter
      Increases all color values
 
     .PARAMETER Degree
      Amount to add or subtract. Default value: 20
 
        .EXAMPLE
      PS C:\> Set-ISEColor -Cooler
 
            Deletes an ISE theme from the registry
 
     .NOTES
            Part of the ISEColorThemeCmdlets.ps1 Script by Jeff Pollock
            http://Lifeinpowerhsell.blogspot.com
            http://gallery.technet.microsoft.com/ISE-Color-Theme-Cmdlets-24905f9e
    #>


}