Discussion on:

Message 6 of 7
0 Votes
+ -
PowerShell Script
I wrote a Windows PowerShell script to do the same type of thing as these programs. I scheduled a task which runs all day. The quotes.txt file was written in Notepad, with a text on each line.

#PowerShell Script: StretchAlarm.ps1
### Configure a Scheduled Task to Run at Logon.
### Scheduled Task Actions: Powershell.exe -WindowStyle "Hidden" -noprofile -file c:\scripts\StretchAlarm.ps1

$QuoteFile = "c:\scripts\quotes.txt"

# If no time set, set default of 30 minutes
If (!$args)
{
$DelayInMin = 30
}
Else
{
$DelayInMin = $args[0]
}

#If Quote file exists load it else set to default quote.
$FileExists = Test-Path $QuoteFile
If ($FileExists -eq $true)
{
#Read in quotes file
$quotes = Get-Content $QuoteFile
}
Else
{
$quotes = "Have a great day!"
}

# Function: Displays the attention message box & checks to see if the user clicks the ok button.
function Show-MessageBox ($title, $msg) {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[Windows.Forms.MessageBox]::Show($msg, $title, [Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information, [System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::DefaultDesktopOnly) | Out-Null
}

# Wait X minutes then show message and play sound, repeat every X minutes once OK pressed - Loop until end of day.
Do
{
$waitMinutes = $DelayInMin
$startTime = get-date
$endTime = $startTime.addMinutes($waitMinutes)
$timeSpan = new-timespan $startTime $endTime
Start-Sleep $timeSpan.TotalSeconds

# Play System Sound
[system.media.systemsounds]::Exclamation.play()
#Display a random quote from Quote file.
$quote = get-random -inputobject $quotes -SetSeed ((Get-Date).millisecond)
Show-MessageBox Reminder "Time to Stretch`n(Body, Mind & Spirit)`n`n $quote"

}
# Loop until 6pm
Until ($startTime.hour -eq 18)
Posted by Craig_B
4th Dec