Scheduling a macro to stop?
Moderators: Dorian (MJT support), JRL
Scheduling a macro to stop?
Can someone show me how to add script to a macro , to make it stop at a certain time? My macro start's with label>start .......{script} ......goto>start.. I have it running while i am away, it just keeps repeating itself, but at a certain time i would like it to stop. Any help would be appreciated..
Check out the GetTime> function.
You need to try GetTime> and see what kind of output it provides on your computer. It's output will be based upon your OSs regional settings. On my computer, GetTime> shows 6:00 pm as 06:00:00 PM. Since the seconds go by so fast I'd strip them out with midstr> and just use the first 5 chars and the AM/PM designation.
Then somthing like this will stop your script at 6:00pm:
Hope this helps,
Dick
You need to try GetTime> and see what kind of output it provides on your computer. It's output will be based upon your OSs regional settings. On my computer, GetTime> shows 6:00 pm as 06:00:00 PM. Since the seconds go by so fast I'd strip them out with midstr> and just use the first 5 chars and the AM/PM designation.
Then somthing like this will stop your script at 6:00pm:
Code: Select all
Label>start
{script}
GeTime>now
MidStr>%now%,1,5,time
MidStr>%now%,10,2,mer
Concat>time,%mer%
If>%time%=06:00PM,finish
Wait>0.01
goto>start
Lable>finish
Dick
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Or use Hour and Min functions:
Label>start
..
..
..
Hour>h
Min>m
If>%h%%m%1800,start
Label>start
..
..
..
Hour>h
Min>m
If>%h%%m%1800,start
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
If you use Marcus' suggestion to use hour> and min> functions and put them together as he has done, the result is a number. In Macro Scheduler you can test numbers using "equal to" or"not equal to" or "greater than" or "less than".
you could try something like:
Label>start
{script}
Hour>h
Min>m
If>%h%%m%>1800,finish
goto>start
Label>finish
This will be limited to midnight when the number will start back at zero. This can be accomodated if needed by camparing dates as well.
Hope this helps,
Dick
you could try something like:
Label>start
{script}
Hour>h
Min>m
If>%h%%m%>1800,finish
goto>start
Label>finish
This will be limited to midnight when the number will start back at zero. This can be accomodated if needed by camparing dates as well.
Hope this helps,
Dick
Yes, I see that there is a problem with what I posted for you. If you want the script to stop at 1:00 am and you start it anytime after 1:00 am on the same day it quits immediately. Sorry, I know better than to blurt. It always gets me into trouble.
I'll work on it a bit and come up with a solution for you if someone else doesn't post one first.
My apologies,
Dick
I'll work on it a bit and come up with a solution for you if someone else doesn't post one first.
My apologies,
Dick
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
There is an easier way using a second macro and the scheduler ....
Create an INI file that looks something like this:
[MyMacro]
OkToRun=1
Make your main macro look like this
If OkToRun is still 1 the macro will loop back to the start.
Now, create another macro with just one line:
EditIniFile>myinifile.ini,MyMacro,OkToRun,0
And schedule this macro for when you want the main macro to stop.
Schedule your main macro for when you want it to run.
Be sure to modify ini file name, path etc to suit your requirements.
Hope this makes sense.
Create an INI file that looks something like this:
[MyMacro]
OkToRun=1
Make your main macro look like this
Code: Select all
EditIniFile>myinifile.ini,MyMacro,OkToRun,1
Label>Start
..
.. your code here
..
ReadIniFile>myinifile.ini,MyMacro,OkToRun,OkToRun
If>OkToRun=1,Start
Now, create another macro with just one line:
EditIniFile>myinifile.ini,MyMacro,OkToRun,0
And schedule this macro for when you want the main macro to stop.
Schedule your main macro for when you want it to run.
Be sure to modify ini file name, path etc to suit your requirements.
Hope this makes sense.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
I see that an alternate solution has come forward and that is good. However I promised a script and for posterity sake here it is. This script will detect the current time each time the script loops and will compare it to a predefined stop time. If the script is started today before the stop time, the script will stop today when the stop time is reached. If the script is started today after the start time, the script will stop tomorrow when the stop time is reached.
I have commented the script to hopefully demonstrate what it is doing as it is doing it. I'm also posting the exact same thing without the comments so it doesn't look so daunting.
Edit--turn off HTML when posting a script....
Hope this is helpful,
Dick
------------------------------------------------------------------------------
//user/script author sets variable "killtime" to time for stopping script
//using military time format
Let>killtime=1800
//script gets current time
hour>h
Min>m
Let>curtime=%h%%m%
//Script compares killtime and curtime
//If the current time is less than the kill time
//script sets variable "StopFlag" to 0
//this means that during this day the program will be stopped
//when the preset time is reached
//
//If the current time is greater than or equal to the kill time
//script sets variable "StopFlag" to 1
//this means that during this day the program will not be stopped
//the StopFlag variable will be set to zero at midnight
//and the program can then be stopped when the current time
//equals or exceeds the preset time.
If>%killtime%StopFlag=0
EndIf
//Run body of script
Label>start
wait>0.1
{script}
//script gets current time
Hour>h
Min>m
Let>curtime=%h%%m%
//Script compares current time with killtime
//AND reads setting of variable "StopFlag"
//If variable "StopFlag" is zero and current time is
//equal or greater than the desired stop time
//the program stops.
If>{(%curtime%>=%killtime%)and(%StopFlag%=0)}
goto>finish
EndIf
//Script sets the value of variable "StopFlag" to 0
//At roughly midnight.
//If your process takes more than one minute
//you may need to alter the number in the next line
//to 2359 or 2358
If>%curtime%=0000
Let>StopFlag=0
EndIf
goto>start
Label>finish
MDL>done
I have commented the script to hopefully demonstrate what it is doing as it is doing it. I'm also posting the exact same thing without the comments so it doesn't look so daunting.
Edit--turn off HTML when posting a script....
Hope this is helpful,
Dick
------------------------------------------------------------------------------
//user/script author sets variable "killtime" to time for stopping script
//using military time format
Let>killtime=1800
//script gets current time
hour>h
Min>m
Let>curtime=%h%%m%
//Script compares killtime and curtime
//If the current time is less than the kill time
//script sets variable "StopFlag" to 0
//this means that during this day the program will be stopped
//when the preset time is reached
//
//If the current time is greater than or equal to the kill time
//script sets variable "StopFlag" to 1
//this means that during this day the program will not be stopped
//the StopFlag variable will be set to zero at midnight
//and the program can then be stopped when the current time
//equals or exceeds the preset time.
If>%killtime%StopFlag=0
EndIf
//Run body of script
Label>start
wait>0.1
{script}
//script gets current time
Hour>h
Min>m
Let>curtime=%h%%m%
//Script compares current time with killtime
//AND reads setting of variable "StopFlag"
//If variable "StopFlag" is zero and current time is
//equal or greater than the desired stop time
//the program stops.
If>{(%curtime%>=%killtime%)and(%StopFlag%=0)}
goto>finish
EndIf
//Script sets the value of variable "StopFlag" to 0
//At roughly midnight.
//If your process takes more than one minute
//you may need to alter the number in the next line
//to 2359 or 2358
If>%curtime%=0000
Let>StopFlag=0
EndIf
goto>start
Label>finish
MDL>done
Code: Select all
Let>killtime=1800
hour>h
Min>m
Let>curtime=%h%%m%
If>%killtime%<%curtime%
Let>StopFlag=1
Else
Let>StopFlag=0
EndIf
Label>start
wait>0.1
{script}
Hour>h
Min>m
Let>curtime=%h%%m%
If>{(%curtime%>=%killtime%)and(%StopFlag%=0)}
goto>finish
EndIf
If>%curtime%=0000
Let>StopFlag=0
EndIf
goto>start
Label>finish
MDL>done