Scheduling a macro to stop?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
KJOHNSON1
Newbie
Posts: 7
Joined: Thu Jul 13, 2006 5:52 pm

Scheduling a macro to stop?

Post by KJOHNSON1 » Thu Jul 13, 2006 6:07 pm

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..

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jul 13, 2006 7:57 pm

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:

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
Hope this helps,
Dick

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jul 13, 2006 8:38 pm

Or use Hour and Min functions:

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?

KJOHNSON1
Newbie
Posts: 7
Joined: Thu Jul 13, 2006 5:52 pm

Post by KJOHNSON1 » Fri Jul 14, 2006 2:10 pm

Ok, i will try your method JRL, now my script is about 1/2 long, so if i set it up to stop at say 6:00 pm , and it checks time after 6:00 pm, it will still stop? Or is there a way to check time- if greater than 6:00 pm stop?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jul 14, 2006 2:24 pm

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

KJOHNSON1
Newbie
Posts: 7
Joined: Thu Jul 13, 2006 5:52 pm

Post by KJOHNSON1 » Fri Jul 14, 2006 3:31 pm

Well im not shure i understand this script..{i am a noob} ok maybe you could show me what it would look like if i wanted it to stop at 1:00 A.M.? Or 11:59 p.m since that will be the same day?
Thanks again for all the help ..

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jul 14, 2006 3:42 pm

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

KJOHNSON1
Newbie
Posts: 7
Joined: Thu Jul 13, 2006 5:52 pm

Post by KJOHNSON1 » Fri Jul 14, 2006 4:31 pm

Oh, it no problem at all, dont sweat it, you have helped alot already. But if you do come up with a solution that would be great...
p.s. Stopping at 11:59 pm would be very acceptible if you could show me how that script would look..

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jul 14, 2006 4:55 pm

Is the issue that it must stop at a particular time, or would it also work to have it stop after a certain amount of run(elapsed) time? Elapsed time gets over the issue with midnight.

KJOHNSON1
Newbie
Posts: 7
Joined: Thu Jul 13, 2006 5:52 pm

Post by KJOHNSON1 » Fri Jul 14, 2006 5:38 pm

Well, elapsed time would be fine if it was not hard to change daily, because the macro might start at 5:00 one day, and 8:00 another day, but each day i need it to stop at the same time..

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jul 14, 2006 5:50 pm

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

Code: Select all

EditIniFile>myinifile.ini,MyMacro,OkToRun,1
Label>Start

..
.. your code here
..

ReadIniFile>myinifile.ini,MyMacro,OkToRun,OkToRun
If>OkToRun=1,Start
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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

KJOHNSON1
Newbie
Posts: 7
Joined: Thu Jul 13, 2006 5:52 pm

Post by KJOHNSON1 » Fri Jul 14, 2006 6:01 pm

Nice, i will try that, also you just gave me another ideal, I never thought of using another macro. Thanks..

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jul 14, 2006 9:38 pm

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

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

KJOHNSON1
Newbie
Posts: 7
Joined: Thu Jul 13, 2006 5:52 pm

Post by KJOHNSON1 » Fri Jul 14, 2006 9:58 pm

Impressive....I do believe you have created a solution to my problem.. Thank you all for the time and information..

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts