Saturday, August 19, 2017

Create a sleep timer for Youtube, Vimeo, Netflix etc. on Windows 10

Here are instructions on how to create a Windows 10 sleep timer that will close your browser after a specified time. It's great for those who like to watch Youtube at night.

Just copy and paste this into notepad, then save the file with a .bat file extension, for example sleepbrowser.bat.

The below script will close Firefox after 60 minutes. You can easily edit the delay in minutes. Just edit the row "SET SLEEPDELAYMIN=60".

If you use Chrome, Opera, Internet explorer or Edge, just replace the part 'firefox.exe' with your browser's executable name. This works also as a sleep timer for any other type of program than just browsers. You could make it close Spotify or Winamp as well.

Here is the batch script.

echo off
SET SLEEPDELAYMIN=60

SET /A SLEEPDELAY=60*SLEEPDELAYMIN
echo Will close Firefox after %SLEEPDELAYMIN% minutes
timeout /t %SLEEPDELAY% /nobreak

echo Killing Firefox...
taskkill /F /T /IM firefox.exe


I use the script also to start the BOINC client after closing the browser. So when I'm sleeping, my computer will calculate asteroid paths and try to find possible medicines for viruses like Ebola, Zika and HIV.

If you want to start a program after closing the browser, just add something like this:

echo Waiting 10 seconds for Firefox to close
timeout /t 10 /nobreak
echo Starting BOINC...
"c:\program files\BOINC\boinc.exe"


Just replace the "c:\program files\BOINC\boinc.exe" line with the path to the program you want to start.