PowerShell Clock with ShowUI

July 7, 2011

in Microsoft,PowerBoots,PowerShell,Video Tutorial,WPF,WPK

Richard Siddaway posted A PowerShell Clock using WPF and demonstrated some nice features.

  • A windowless window
  • Ticking digital clock
  • Moving the window by clicking and dragging even though it doesn’t have a border

image

The ShowUI Code

Here is the ShowUI code. Note the On_* keys in the hash table. They handle the mouse button events and the windows load event where I register a PowerShell script block that executes every half a second. This updates the time and enables the ticking digital clock.

Richard’s solution has the advantage that he can deploy it and it should work on any windows system that has the latest .NET runtime.

My solution requires the ShowUI module to be installed on the target machine.

The advantages to my solution, IMHO, are no XAML, increased value per line of code and it’s all PowerShell.

Check out both solutions and ShowUI.

Import-Module ShowUI            

$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 = (Get-Date).ToString("T")
        } -Run -In "0:0:0.5"
    }
}            

$labelAttributes = @{
    Content = (Get-Date).ToString("T")
    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
        )
    )
}

Related Topics

{ 4 trackbacks }

AN easier clock | Richard Siddaway's Blog
07.08.11 at 12:32 pm
Richard Siddaway's Blog
07.08.11 at 12:33 pm
Start-Scripting
07.12.11 at 8:36 pm
Updated, Hippy Dippy PowerShell Clock with ShowUI
07.13.11 at 8:03 pm

{ 3 comments… read them below or add one }

Ravikanth 07.08.11 at 1:05 am

Why does this ignore font weight/size when I replace -Show with -AsJob?

Doug Finke 07.08.11 at 8:08 am

Thanks Ravi. Can you put that up on the CodePlex site? Then we can get more eyes on it.

Thanks

Doug

Ravikanth 07.08.11 at 8:45 am

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Contrat Creative Commons

© 2007-2012, Doug Finke