-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDelay.ps1
76 lines (63 loc) · 2.02 KB
/
Delay.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
# Copyright (c) iQubit Inc.
<#
.SYNOPSIS
Perform specified delay
.DESCRIPTION
Call Delay Binary to Display timer and perform the delay
Show a balloon notification on System Tray after specified time elapses
ToDo: later, may be, update this with a C# implementation along with a binary
.PARAMETER Time
how long to delay
.EXAMPLE
Delay 2 "task completed"
Delay 5
tag: windows-only
#>
[CmdletBinding()] Param (
[Parameter(Mandatory=$true)] [string] $Time,
[string] $Msg)
<#
.SYNOPSIS
Main function
.DESCRIPTION
Check previous commentary (top)
.NOTES
References
- https://technet.microsoft.com/en-us/library/ff730952.aspx
Icon,
- https://msdn.microsoft.com/en-us/library/system.windows.forms.tooltipicon.aspx
NotifyIcon.ShowBalloonTip Method (Int32)
- https://msdn.microsoft.com/en-us/library/ms160064.aspx
Dispose
- http://techibee.com/powershell/system-tray-pop-up-message-notifications-using-powershell/1865
Component.Dispose Method ()
- https://msdn.microsoft.com/en-us/library/3cc9y48w.aspx
#>
function Main() {
# Validate Script Dir
if (!(Test-Path $PwshScriptDir)) {
'Script Dir: $PwshScriptDir not set!'
return
}
# Retrieving $PwshScriptDir from Params
& ($PwshScriptDir + '\bin\Delay.exe') $Time
# Fork in parallel need to make this one wait too
# Start-Sleep $Time
if ([string]::IsNullOrEmpty($Msg)) {
$Msg = "DT: $Time seconds time up. Switch context now."
}
else {
$Msg = "$Msg `(elapsed ${Time}s`)."
}
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon
$objNotifyIcon.Icon = $PwshScriptDir + "\bin\mdelay_ps_icon.ico"
$objNotifyIcon.BalloonTipIcon = "Info"
$objNotifyIcon.BalloonTipText = $Msg
$objNotifyIcon.BalloonTipTitle = "Delay Timer"
$objNotifyIcon.Visible = $True
$objNotifyIcon.ShowBalloonTip(2000)
Start-Sleep -Milliseconds 2001
$objNotifyIcon.Dispose()
}
Main