Last active
November 6, 2024 10:12
-
-
Save thygrrr/f3f446d5dd64165472c36aa59f4c11a7 to your computer and use it in GitHub Desktop.
Powershell Pomodoro Timer, locks the workstation when timer expires
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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