READING TIME: 3 MINUTES
In this guide, I’m going to show you how to run a batch file during a certain time window. This also works for .CMD files, Powershell files, or really any other program you want to run. I am purposely not using Task Scheduler for this.
Here’s my use case:
I have Blue Iris+Deepstack installed on my Server 2019 server. When a “person” object is detected, I have a Blue Iris alert set to run a
Telegram_Upload.cmd file that sends an image of the detected motion in my driveway to my Telegram group chat.
However, I don’t want this to trigger all day, everyday, as my family and I often play in the driveway, when we bring in groceries, etc. Instead, I only want the Telegram_Upload.cmd file to trigger if it’s during a certain window, such as if motion is detected overnight.
If you’d like to do something similar, here’s how to do it:
How It Works
Instead of setting my Blue Iris alert to run the Telegram_upload.cmd command directly, I’m instead going to point my alert at a new file that will call the Telegram_upload.cmd if during a certain time frame.
To do this, you just need to create a simple script like I have below.
Run File At A Specific Time Script
Open Notepad. Paste in the code below. The code below will only call the script if between the hours of 11pm and 7am.
Note that this code doesn’t support minutes, just full hours. So, you can’t have it run between 11:45pm and 11:30am.
SET hour=%time:~0,2% SET shouldrun=True IF %hour% geq 23 SET shouldrun=False IF %hour% leq 7 SET shouldrun=False IF "%shouldrun%"=="True" ( CALL "S:\BlueIris\Telegram_Upload\Telegram_upload.cmd" )
Just change the path to your batch file, Powershell script, or program and adjust the time window.
If True, this new file will call the script correctly and run. If false, it will not run it.
After you adjust the parameters to your liking, go to File > Save As. Name it
Telegram_Upload_TimeWindow.cmd. You can store this file anywhere you want on your local server, but if you found this post from my How To Send Blue Iris Images to Telegram guide, I recommend putting it in the same directory, like this:
Edit Blue Iris Alert
Then, in Blue Iris, right click a camera > camera settings. Switch to the Alerts tab.
Under the Actions setting, click On Alert.
Double-click your action and change the file from running Telegram_Upload.cmd directly to your new
That’s all there is to it! You will now only receive Telegram alerts from Blue Iris if it’s during the specified time frame.