help for chain script

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
koleviko
Junior Coder
Posts: 45
Joined: Thu Nov 20, 2008 2:59 pm

help for chain script

Post by koleviko » Fri Nov 21, 2008 2:03 pm

I want to do with the script chain condition, but does not work. It is only the first part of the cycle. Here here illustrates what it is. Help me


Label>c

IfWindowOpen>Notepad*,a
IfWindowOpen>Document - WordPad*,b

Label>a
WaitWindowOpen>Notepad*
WindowAction>1,Notepad*
Goto>c

Label>b
WaitWindowOpen>Document - WordPad*
WindowAction>1,Document - WordPad*
Goto>c

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

Post by Marcus Tettmar » Fri Nov 21, 2008 2:56 pm

Using labels is messy - your code will always progress through the first label, so if you use labels you need more Gotos to avoid it. Much nicer to use subroutines:

Code: Select all

Label>main_loop
  IfWindowOpen>Notepad*,a
  IfWindowOpen>Document - WordPad*,b
Goto>main_loop

SRT>a
  WindowAction>1,Notepad*
End>a

SRT>b
  WindowAction>1,Document - WordPad*
End>b
And you don't need WaitWindowOpen. If IfWindowOpen returns true then the window must be open so you don't need to wait for it to open.

However, you could avoid duplication (all your subs do the same thing - the only thing that changes is the window title) like this:

Code: Select all

Label>main_loop
  GoSub>maxWin,Notepad*
  GoSub>maxWin,Document - WordPad*
Goto>main_loop

SRT>maxWin
  IfWindowOpen>%maxWin_Var_1%
    WindowAction>1,%maxWin_Var_1%
  Endif
End>maxWin
Just add more GoSub calls for the windows you want to add to the "chain".
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: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Nov 21, 2008 3:00 pm

Study the sequence of events this code performs. It will only ever act on Notepad unless you have Wordpad open and Notepad closed when you start the script.

What version of Macro Scheduler do you have? If you have OnEvent>Window_Open available to you try using that function instead of trying to create logic using labels.

Its possible to do what you're asking with labels but it will require a lot more coding. If you don't have OnEvent> at least use subroutines rather than labels.

On another subject, I realize that your posted code is just a sample, but in general, you will save yourself trouble in the future if you DO NOT use single characters to name anything in Macro Scheduler. Label>a would be better as label>a1 and even better as label>NotePadIsOpen

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