diff --git a/icon_off.png b/icon_off.png new file mode 100644 index 0000000..3c27f7c Binary files /dev/null and b/icon_off.png differ diff --git a/icon.png b/icon_on.png similarity index 100% rename from icon.png rename to icon_on.png diff --git a/systray.ps1 b/systray.ps1 index 495ba18..f569eb5 100644 --- a/systray.ps1 +++ b/systray.ps1 @@ -1,11 +1,14 @@ [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null -$ICON = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $pwd '\icon.png'))).GetHicon()) # Convert my png (bitmap) to an icon -# $ICON = [System.Drawing.Icon]::ExtractAssociatedIcon() # Feel free to use a system icon +$ICON_ON = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $pwd '\icon_on.png'))).GetHicon()) # Convert my png (bitmap) to an icon +$ICON_OFF = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $pwd '\icon_off.png'))).GetHicon()) +# $ICON_ON = [System.Drawing.Icon]::ExtractAssociatedIcon() # Feel free to use a system icon +# $ICON_OFF = [System.Drawing.Icon]::ExtractAssociatedIcon() function NewTrayIcon(){ $TrayIcon = New-Object System.Windows.Forms.NotifyIcon $TrayIcon.Text = "NumLock on" - $TrayIcon.Icon = $ICON + $TrayIcon.Icon = If ([console]::numberlock) {$ICON_ON} Else {$ICON_OFF} + $TrayIcon.Visible = $true $TrayIcon.Add_Click({ # In case our script stops working, allow user to kill icon so that their system tray isn't cluttered $TrayIcon.Visible = $false @@ -17,13 +20,7 @@ function NewTrayIcon(){ } While ($true) { While ($TrayIcon.Text) { - If ([console]::numberlock) { - If (!$TrayIcon.Visible) { - $TrayIcon.Visible = $true - } - } ElseIf ($TrayIcon.Visible) { - $TrayIcon.Visible = $false - } + $TrayIcon.Icon = If ([console]::numberlock) {$ICON_ON} Else {$ICON_OFF} Start-Sleep -Seconds 1 # Set this to whatever polling rate you want. } $TrayIcon = NewTrayIcon