If Statements and Time

July 11, 2010 at 08:58:31
Specs: Windows XP
I was wondering if there is a way to execute certain programs at certain times without using Scheduled Tasks. Basically, I want reminders to pop up at certain times in Notepad, but I do not want to fill up Scheduled Tasks with text files and such.

My idea is to, at certain times, create text files containing reminders and open them so I can see them. I can do everything except call the times. For example: In Scheduled Tasks, I start this "master" batch file, and it starts looping. (Just an example) At two o'clock every day let's just say I have a meeting I need to go to. At two o'clock, the batch file would then recognize the time and stop looping, create the reminder, and move on. How do I store the time in a variable and then use it in an if statement? Is it possible?


See More: If Statements and Time

Report •


#1
July 11, 2010 at 14:24:39
a pretty nifty challenge!
Here's the way I would set it up. Your master-tasker batchfile looks like this:

@echo off & setlocal enabledelayedexpansion
:: this will execute the current "task"
set xx=1
if "%1" equ "" goto :redo
call :---%1
:: this will sort all the tasks labels (which are times) locating the current one
for /f "tokens=1,2 delims=-:" %%a in ('sort tasker.bat ^| findstr /b /n ":---%1"') do set xx=%%a & echo %%b
set /a xx+=1
:: now sort again, locating the next one after the current one
:redo
for /f "tokens=1* delims=-:" %%a in ('sort tasker.bat ^| findstr /b /n ":---" ^| findstr /b "!xx!::---" ^|^| echo a:eof') do echo %%a %%b & set nextime=%%b
if %nextime% equ eof set xx=1 & goto :redo
:: now reset tasker to launch at the new time in the task scheduler
echo at %nextime% "\tasker.bat %nextime%"
goto :eof
:---10:15
echo COFFE BREAK!!!
goto :eof
:---13:00
notepad \msg1
goto :eof
:---14:00
start reminder.wav
goto :eof
:---17:00
echo TIME TO GO HOME, WORK IS DONE FOR TODAY YAAAY!
goto :eof
::------ end
note that the times-labels do not have to be in chron. order.
If a person were ambitious, they would also write a small "tasker maintenance"
batch to list all the times and allow deletion or addition of new, but hell,
EDIT is plenty easy to use anyway.


Report •

#2
July 11, 2010 at 16:45:29
Wonderful! Thanks.

Report •

#3
July 12, 2010 at 14:44:46
With the caveat that looping for a long time is problematic.

===============================

@echo off & setLocal EnableDELAYedeXpansion

:loop
ping -n 1 -w 3600000 1.1.1.1 > nul
if "!TIME:~1,2!" equ "14" start myfile.txt && goto :eof
goto :loop


=====================================
Helping others achieve escape felicity

M2


Report •
Related Solutions


Ask Question