<# : @echo off mode con: cols=25 lines=5 title Keepawake powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$content = [System.IO.File]::ReadAllText('%~f0'); Invoke-Expression $content" exit /b #> $keyInterval = 59 # SendKeys every n seconds #$frames = '|', '/', '-', '\' #$frameMs = 250 # New spinner frame every n ms <# Other spinner options if the file exists #> $spinnerName = "dwarfFortress" $spinFile = "spinners.json" # From https://raw.githubusercontent.com/sindresorhus/cli-spinners/refs/heads/main/spinners.json $wsh = New-Object -ComObject WScript.Shell $width = [Console]::WindowWidth function center([string]$text) { $pad = [math]::Max(0, [math]::Floor(($width - $text.Length) / 2)) # Pad to width-1 to ensure text never wraps (' ' * $pad + $text).PadRight($width -1) } function Draw([int]$row, [string]$text, [string]$color) { [Console]::SetCursorPosition(0, $row) Write-Host (Center $text) -NoNewline -ForegroundColor $color } function FindSpinner([string]$fname, [string]$spinnerName) { if ($fname -eq $null -or $spinnerName -eq $null) { $frames = '||', '/', '-', '\' $frameMs = 250 return $frames, $frameMs } $allSpinners = Get-content $fname | convertfrom-json # -encoding utf8 $ourSpinner = $allSpinners.$spinnerName $frameMs = $ourSpinner.interval $frames = $ourSpinner.frames return $frames, $frameMs } function SendChars() { # Send Shift+F15 - this is the least intrusive key combination I can think of and is also used as default by: # http://www.zhornsoftware.co.uk/caffeine/ # Unfortunately the above triggers a malware alert on Sophos so I needed to find a native solution - hence this script... $wsh.SendKeys('+{F15}') } # # Actual loop # try { [Console]::CursorVisible = $false Clear-Host Draw 1 'Keeping awake' Green $frames, $frameMs = FindSpinner $spinFile $spinnerName $i = 0 $sw = [Diagnostics.Stopwatch]::StartNew() SendChars while (1) { if ($sw.Elapsed.TotalSeconds -ge $keyInterval) { SendChars $sw.Restart() } $remaining = $keyInterval - [int][math]::Floor($sw.Elapsed.TotalSeconds) Draw 2 $frames[$i] Cyan Draw 3 "next in ${remaining}s" DarkGray $i++ $i = $i++ % $frames.Count Start-Sleep -Milliseconds $frameMs } } finally { [Console]::CursorVisible = $true }