Skip to content

Instantly share code, notes, and snippets.

@saggie
Last active December 21, 2016 15:22
Show Gist options
  • Save saggie/073c716267a2cb411d7cb7ce6f49b045 to your computer and use it in GitHub Desktop.
Save saggie/073c716267a2cb411d7cb7ce6f49b045 to your computer and use it in GitHub Desktop.
Wait for instant noodles get done
param([int]$Minutes = 3)
$appName = "Wait-Noodles"
# create a task tray icon
Add-Type -AssemblyName System.Windows.Forms
$notifyIcon = New-Object System.Windows.Forms.NotifyIcon
# get an icon image from powershell.exe
$psExeFilePath = Join-Path $Script:PSHOME "powershell.exe"
$notifyIcon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($psExeFilePath)
# notify the start
$notifyIcon.Visible = $true
$notifyIcon.ShowBalloonTip(5000, "Start", "$appName has started.", "Info")
# wait
$startTicks = (Get-Date).Ticks
$targetSec = $Minutes * 60
do
{
$elapsedSec = ((Get-Date).Ticks - $startTicks) / 10000000
$remainingSec = $targetSec - [int]$elapsedSec
$notifyIcon.Text = "$appName - Remaining $remainingSec seconds"
Start-Sleep -Seconds 1
}
while ($elapsedSec -lt $targetSec)
# notify the end
$notifyIcon.ShowBalloonTip(5000, "End", "$appName has ended.", "Info")
$notifyIcon.Visible = $false
@saggie
Copy link
Author

saggie commented Dec 19, 2016

Usage:

# 3 minutes mode (default)
PS C:\> .\Wait-Noodles

# 5 minutes mode
PS C:\> .\Wait-Noodles 5

# Background mode
PS C:\> powershell.exe -WindowStyle Hidden -STA .\Wait-Noodles.ps1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment