2424 . PARAMETER AlarmInterval
2525 In what time interval to write warnings and send sound.
2626
27+ . PARAMETER RandomInterval
28+ Randomizes the interval between two signal sounds.
29+
2730 . PARAMETER MinFrequency
2831 The minimum frequency of the beeps.
2932 Must be at least one lower than MaxFrequency.
3437 Must be at least one higher than MaxFrequency.
3538 Increase delta to play random frequency sounds on each beep.
3639
40+ . PARAMETER DisableScreensaver
41+ Disables the screensaver while the timer is pending.
42+ This only works on Windows and has the command pretend to be a video & backup application, preventing untimely activation of a screensaver.
43+
3744 . EXAMPLE
3845 PS C:\> timer 170 Tea
3946
4047 After 170 Duration give warning that the tea is ready.
4148#>
49+ [Alias (' timer' )]
4250 [Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSUseShouldProcessForStateChangingFunctions" , " " )]
4351 [CmdletBinding ()]
4452 param (
6068 [int ]
6169 $AlarmInterval = 250 ,
6270
71+ [switch ]
72+ $RandomInterval ,
73+
6374 [int ]
6475 $MinFrequency = 2999 ,
6576
6677 [int ]
67- $MaxFrequency = 3000
78+ $MaxFrequency = 3000 ,
79+
80+ [switch ]
81+ $DisableScreensaver
6882 )
6983
7084 begin
7185 {
7286 $start = Get-Date
7387 $end = $Duration.Value
88+ # Allow conveniently specifying absolute times for the day after
89+ if ($end -lt $start ) { $end = $end.AddDays (1 ) }
7490
7591 function Get-FriendlyTime
7692 {
111127 while ($end -gt (Get-Date ))
112128 {
113129 Start-Sleep - Milliseconds 500
130+ if ($DisableScreensaver ) { [PSUtil.Utility.UtilityHost ]::DisableScreensaver() }
114131
115132 if (-not $NoProgress )
116133 {
129146 while ($countAlarm -lt $AlarmCount )
130147 {
131148 Write-PSFHostColor - String " (<c='sub'>$countAlarm </c>) ### <c='em'>$ ( $Message ) </c> ###"
149+ if ($DisableScreensaver ) { [PSUtil.Utility.UtilityHost ]::DisableScreensaver() }
132150 [System.Console ]::Beep((Get-Random - Minimum $MinFrequency - Maximum $MaxFrequency ), $AlarmInterval )
133- Start-Sleep - Milliseconds $AlarmInterval
151+ if ($RandomInterval ) { Start-Sleep - Milliseconds (Get-Random - Minimum $AlarmInterval - Maximum ($AlarmInterval * 2 )) }
152+ else { Start-Sleep - Milliseconds $AlarmInterval }
134153 $countAlarm ++
135154 }
136155 }
137- }
138- Import-PSUAlias - Name " timer" - Command " Start-PSUTimer"
156+ }
0 commit comments