Strange Macro Behavior

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Dan
Newbie
Posts: 5
Joined: Fri Jan 11, 2008 6:45 pm

Strange Macro Behavior

Post by Dan » Fri Jan 11, 2008 10:20 pm

Macro below works "perfectly" from the run button inside MS9.x
If I try running it from the Quick Launch menu in the task bar- it gets about halfwaythrough (x=2)and stops. If I use the hotkey from the main Windows screen, it just opens the event viewer and stops there???

Did I miss something (again)?

Dan

Code: Select all

run>eventvwr.exe
WaitWindowOpen>Event Viewer
SetFocus>Event Viewer
Let>x=0
Repeat>x
		Let>x=x+1
		Press Down
		Press Alt
		Send>acn
		Release Alt
Until>x=8

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

Post by Marcus Tettmar » Fri Jan 11, 2008 10:59 pm

I see you are sending ALT-acn. On my PC ALT-A opens the Action menu. Alt-C performs "Clear all events.." which causes a new dialog to open. Alt-N then selects the "No" button.

Your script is trying to send ALT-acn all in one go - the script is sending this within milliseconds of each other. But that new dialog is going to take longer than that. Basically you're not making the script wait for that dialog to appear and those keystrokes are just going nowhere too fast. You want to do:

//Do Action/Clear...
Press ALT
Send>ac
Release ALT

//Wait for the new dialog
WaitWindowChanged>0

//Now I can send ALT-N
Wait>0.2
Press ALT
Send>n
Release ALT

//Now I should wait until I know that dialog has gone again
WaitWindowChanged>0

Basically you need to allow time for the keystrokes to have an affect before you continue to send more keystrokes. If you send keystrokes before the target window has appeared to accept them nothing is going to happen. If you send a bunch of keystrokes without any breathing space between them the target window may not get a chance to process them.

So, I would do:

Code: Select all

Run>eventvwr.exe
WaitWindowOpen>Event Viewer
Let>x=0
Repeat>x
  SetFocus>Event Viewer
  Let>x=x+1
  Press Down

  //There's probably a better way to do this but you need a decent 
  // delay here because it can take a while for the event list to populate
  // when you go down to the next event log
  Wait>2

  //Do Action/Clear...
  Press ALT
  Send>ac
  Release ALT

  //Wait for the new dialog
  WaitWindowChanged>0

  //Now I can send ALT-N
  Wait>0.2
  Press ALT
  Send>n
  Release ALT

  //Now I should wait until I know that dialog has gone again
  WaitWindowChanged>0

Until>x=8
Note I've added a delay after the Press Down. It can take a while for the event list to populate. A fixed delay is not the most reliable method as we cannot guarantee that this is ever enough. Though for unattended automation we usually wouldn't care if we made it wait 10 seconds longer than necessary as we won't be watching it anyway. There will be other ways to wait exactly the precise amount of time - probably by capturing text from the status bar/columns or using image recognition. But keep it simple to begin with by using a fixed delay.

I've also put the SetFocus inside the loop to avoid any situation where something else might steal the focus while the macro is running.

Please read Scripting Windows for Beginners in the help file which explains all the concepts I've used above which you will need for automating most tasks. Also read this:
http://www.mjtnet.com/blog/2006/01/17/h ... on-script/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Dan
Newbie
Posts: 5
Joined: Fri Jan 11, 2008 6:45 pm

Post by Dan » Fri Jan 11, 2008 11:54 pm

Thanx again for your help. It is late Friday, so I will try this out when I come to work next Monday and let you know how it works.

Dan

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