Skip to content

Instantly share code, notes, and snippets.

@thygrrr
Last active January 28, 2024 20:49
Show Gist options
  • Save thygrrr/f3f446d5dd64165472c36aa59f4c11a7 to your computer and use it in GitHub Desktop.
Save thygrrr/f3f446d5dd64165472c36aa59f4c11a7 to your computer and use it in GitHub Desktop.
pomodoro.ps1 - Powershell Pomodoro Timer, locks the workstation when timer expires
# spdx-license-identifier Unlicense
if ($args.count -eq 0)
{
write-host "Pomodoro Timer that locks the workstation (screen) when done."
write-host "Usage: pomodoro.ps1 <minutes> ['activity']"
write-host "Example: pomodoro.ps1 5 try out new script"
Exit
}
# Select default activity if none is specified, otherwise concat all optional arguments
$Activity = ($args[1] && $args[2..22]) ?? "Pomodoro"
$Activity = $Activity -join " "
# Start and update the timer until the specified duration is reached
$Start = Get-Date
$Duration = New-TimeSpan -Minutes $args[0]
$End = $Start + $Duration
Do{
Start-Sleep -Seconds 1
$DisplayTime = New-TimeSpan -Start $(Get-Date) -End $End
$Time = "{0:D2}:{1:D2}" -f ($DisplayTime.Minutes), ($DisplayTime.Seconds)
Write-Progress $Time -Activity $Activity
}
While((Get-date) -lt $End)
# Lock the Screen
rundll32.exe user32.dll,LockWorkStation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment