PowerShell & Windows Task Scheduler: Trigger Audio Clip at Set Time Daily

Inspired by a scene in The Office, Season 8, Episode 6 where Andy plays Semisonic’s “Closing Time” at the end of every workday, I decided to configure my computer to automatically do the same.

The base script is pretty succinct. It just needs to be pointed to a .wav file near the end of the first line. The song is exactly 4 minutes long, so I had it start playing at 4:56 to conclude exactly at 5.

$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '$PlayWav=New-Object System.Media.SoundPlayer; $PlayWav.SoundLocation="C:\Users\michael\Music\ClosingTime.wav"; $PlayWav.playsync()'
$trigger =  New-ScheduledTaskTrigger -Weekly -WeeksInterval 1 -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday -At 4:56pm
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "PlayClosingTime" -Description "A fun reminder that the workday is over!"

We can now see the task registered in Task Scheduler:

References:

https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtasktrigger?view=win10-ps

https://social.technet.microsoft.com/Forums/lync/en-US/ebdba49f-9516-4059-8368-5db6fb367013/scheduled-task-trigger?forum=winserverpowershell

PowerTip: Use PowerShell to play WAV files

Use PowerShell to Create Scheduled Tasks

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.