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: