"Run When" Problem and Question

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

Post Reply
vondee
Newbie
Posts: 3
Joined: Sat Jul 19, 2008 4:35 pm

"Run When" Problem and Question

Post by vondee » Sat Jul 19, 2008 5:04 pm

Here's an issue I'm experiencing with scheduling a macro to run.

I'd like to turn on the PC and have a macro start running every hour after that until the PC is turned off. If I turn the PC on at 7:00am, it will boot up by 7:10am and macro scheduler will load and the macro will run at about 7:11am. Then it should run at 8:11am, 9:11am, through the rest of the day. I don't care about the actual time it runs. It just needs to run once each hour after the PC starts up; whether I turn the PC on at 6:30am, 7:15am, or 2:37pm.

Here's the problem I am having. What "Run When" does is forces the time in "At" to pass first before the "Repeat Every" option kicks in. This means that if I put 7:00am in the "At" field, and put 60 in the "Repeat Every" field, this is all fine... as long as I turn the PC on before 7:00am. But if I turn the PC on at 7:05am, the "At" time is never seen (because 7:00am is passed, its 7:05am now) and the "Repeat Every" cycle never kicks in.

Is there a way to have a macro run at a specified interval (in my case, every 60 minutes), starting at the time you turn the PC on? Long explanation for a simple concept.

Thanks for any insight here.

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

Post by Marcus Tettmar » Mon Jul 21, 2008 8:56 am

Actually, if you have a start time of 0700 and a repeat of 60 mins and start the PC at 0705 the macro will schedule for 0800, then 0900 etc. Because 0800 is the next available interval. Make sure under Advanced options you have "Run at scheduled start time" and "repeat continuously".
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by JRL » Mon Jul 21, 2008 4:43 pm

I would handle this by running a second macro that starts when Windows starts and have it schedule the primary macro.

- Create a new macro that contains the script below.
- Select "Macro Properties" by double clicking on the macro name from the main menu.
- Select the "Run When" tab>.
- Pick the "Advanced Options" button.
- Pick the "Run Immediately Anyway" radio button.
- Pick Ok then Ok again.

The macro is now scheduled to run when Windows starts. It will continue to run until it is killed by you. As long as this macro is running, it will run your other macro at any interval you specify up to 1440 minutes.

Read the remarks in the following script. You need to specify the path and file name for the macro you wish to run. You also need to specify the time interval in minutes. Portions of a minute can be specified using a decimal. For example 5.25 would be 5 minutes and 15 seconds.

Code: Select all

//Macro to be scheduled path and file name.
Let>File1=C:\Path\MacroName.scp

//Time in minutes between scheduled Macro runs.
Let>TimeInMinutes=123.25

//If this Macro is already running, close this second instance.
IfWindowOpen>S~heduleDialo~1,EOF

VBSTART
VBEND
VBEval>Timer,starttime

//Dialog to test for this Macro already running.
Dialog>ScheduleDialog1
   Caption=S~heduleDialo~1
   Width=0
   Height=0
   Top=-10000000
   Left=CENTER
EndDialog>ScheduleDialog1

//Start the test for this Macro already running window.
GoSub>DisplayWindow

//Restart the test for this Macro already running window
//if it somehow closes.
OnEvent>WINDOW_NOTOPEN,S~heduleDialo~1,1,DisplayWindow

//Convert minutes between Macro runs to seconds between Macro runs.
Let>SchedTime=%TimeInMinutes%*60

//Initialize DoItTime variable
Let>DoItTime=%starttime%

//Main timer Loop
Label>MainLoop
VBEval>Timer,thistime
If>%thistime%>%DoItTime%,RunMacro
Wait>0.01
Goto>MainLoop

Label>RunMacro
Macro>%file1%
Add>DoItTime,%SchedTime%

//Account for and schedule past Midnight
If>{%DoItTime%>=86400}
  Let>DoItTime=%DoItTime%-86400
  If>DoItTime=0
    Add>DoItTime,.2
  EndIf
  Label>SecLoop
  VBEval>Timer,thistime
  If>thistime>%DoItTime%
    Sub>thistime,86400
  Else
    Label>TreLoop
	VBEval>Timer,thistime
	If>%thistime%>%DoItTime%,RunMacro
	Wait>0.01
	goto>TreLoop
  EndIf
  Wait>0.01
  Goto>SecLoop
EndIf
Goto>MainLoop

SRT>DisplayWindow
  Show>ScheduleDialog1
  WaitWindowOpen>S~heduleDialo~1
END>DisplayWindow

Label>EOF

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