Last month I started playing with WPF to show how a multi-coloured clock could be displayed on screen. This was picked up and an easier version was created by Doug Finke using the ShowUI module from codeplex http://showui.codeplex.com/.
Other links are here
http://msmvps.com/blogs/richardsiddaway/archive/2011/07/08/an-easier-clock.aspx
As well as wanting to know the time I often want to set a count down timer. I did a version of this ages ago using PowerGadgets but if you don’t have that then we can do something with show UI
Import-Module ShowUI function timeleft { $ts = $close - (Get-Date) $time = $ts.ToString() -split "\." $time[0].Substring(3,5) } $close = (Get-Date).AddMinutes(35) $windowAttributes = @{ WindowStartupLocation = "CenterScreen" SizeToContent = "WidthAndHeight" WindowStyle = "None" Background = "Transparent " On_MouseRightButtonDown = { Close-Control} On_MouseLeftButtonDown = { $_.Handled = $true;$window.DragMove() } On_Loaded = { Register-PowerShellCommand -ScriptBlock { $window.Content.Content = timeleft } -Run -In "0:0:0.5" } } $labelAttributes = @{ Content = timeleft FontFamily = "Impact, Arial" FontWeight = 800 FontSize = 90 } New-Window @windowAttributes -AllowsTransparency -Show { Label @labelAttributes -Name Clock -Foreground ( LinearGradientBrush $( GradientStop -Color Red -Offset 1 GradientStop -Color Orange -Offset 0.85 GradientStop -Color Yellow -Offset 0.7 GradientStop -Color Green -Offset 0.55 GradientStop -Color Blue -Offset 0.4 GradientStop -Color Indigo -Offset 0.2 GradientStop -Color Violet -Offset 0 ) ) }
All I changed was to point the Content to the timeleft function instead of get-date. The function takes the closing time – in this case 35 minute from starting and subtracts the current datetime (from get-date). The resultant timespan is converted to a string and split at the millisecond point. The minutes and seconds are extracted as a substring to display
By the way – anyone noticed the deliberate(?) mistake with the colours