Repeat and use WaitWindowOpen for exit of loop

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Esabik
Pro Scripter
Posts: 52
Joined: Wed Jun 15, 2005 8:03 pm
Location: Fairfield, NJ

Repeat and use WaitWindowOpen for exit of loop

Post by Esabik » Wed Jan 03, 2018 6:43 pm

Hi

Is it possible to code a script that is using Repeat with a WaitWindowOpen as the "Until" somehow?? Or is there something similar I am missing?

We have a process running that I would use WaitWindowOpen and when it finishes I would like to end the loop.

ex....
Repeat>r
blah
blah
Until>WaitWindowOpen>Notepad*

Regards....
Just when you thought it was safe to go in the water........:evil:

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

Re: Repeat and use WaitWindowOpen for exit of loop

Post by JRL » Thu Jan 04, 2018 2:01 am

Something like this?

Run this then open Notepad and the script will end. Before you open notepad the message will tell you how long the script has been running


Code: Select all

Let>WW_Result=0
Let>WW_Timeout=0.5
Message>

Repeat>WW_Result
  WaitWindowOpen>Notepad*
  Timer>vTime
  Let>vTime={round(%vTime%/1000)}
  SetControlText>Macro Scheduler Message,TMemo,1,We've been waiting%crlf%%vTime% seconds
Until>WW_Result=TRUE

MDL>Done

User avatar
Esabik
Pro Scripter
Posts: 52
Joined: Wed Jun 15, 2005 8:03 pm
Location: Fairfield, NJ

Re: Repeat and use WaitWindowOpen for exit of loop

Post by Esabik » Thu Jan 04, 2018 4:33 pm

Thank you for posting the info. Though I am not certain how to incorporate that in my script. Can I put the loop in another loop? I am not at an open session, I am waiting for something to finish processing along with using a mouse mover. Sorry if this is a little confusing.

Since I already have a loop I will explain more in the scenario.

We run some MRP processes in our database. Could take as short as 25 minutes or as long as 4 hours. The problem is internally we installed a new server so there is a 30 min timeout. So I wrote a mouse mover script that will keep the session alive beyond the 30 minutes, but I need to come out of the mouse mover after that process finishes and opens Adobe Acrobat for the file export.

old script
==============
Script starts
Process running ( 20 min to 4 hours)
Waitwindowopen>Adobe Acrobat


My intention is to install my mouse mover loop while that process is running and stop the mouse mover when the Adobe opens. Is a SRT a better idea?

Concept script on new timeout server
===============
Script starts
Process running ( 20 min to 4 hours)
Repeat>m
mousemover code
until>??

Waitwindowopen>Adobe Acrobat

So would what you wrote allow the script to come out of the mouse mover loop after adobe opens?

Regards
Just when you thought it was safe to go in the water........:evil:

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

Re: Repeat and use WaitWindowOpen for exit of loop

Post by JRL » Thu Jan 04, 2018 5:24 pm

I am not certain how to incorporate that in my script.
Help for WaitWindowOpen> wrote:The system variable WW_TIMEOUT can be used to set the number of seconds after which this command should timeout. If set to zero (the default) the timeout will not occur and the command will continue indefinitely. If WW_TIMEOUT is used, WW_RESULT will indicate whether or not the command ended successfully. If it timed out WW_RESULT will be set to FALSE. If the window it was waiting for appeared within the timeout setting, the WW_RESULT value will be set to TRUE
So help is telling us that if we use WW_Timeout there will be a WW_Result variable. We can use that variable to control the repeat loop. When Acrobat window opens, WW_Result becomes "TRUE" and the loop ends. Simply place your mouse move code in this loop. Be sure to at least remark your current mouse move loop so it does not run.

Code: Select all

Let>WW_Timeout=0.5

Repeat>WW_Result
  WaitWindowOpen>Adobe Acrobat
  //mousemover code
  //I don't know what you're using,  but this should prevent a Windows screen saver
  //And should not interfere with using the mouse.
  GetCursorPos>CurX,CurY
  MouseMove>CurX,CurY
Until>WW_Result=TRUE

//Adobe opened and the script continues past the repeat loop.

User avatar
Esabik
Pro Scripter
Posts: 52
Joined: Wed Jun 15, 2005 8:03 pm
Location: Fairfield, NJ

Re: Repeat and use WaitWindowOpen for exit of loop

Post by Esabik » Thu Jan 04, 2018 7:04 pm

JRL wrote:

//I don't know what you're using, but this should prevent a Windows screen saver
//And should not interfere with using the mouse.
GetCursorPos>CurX,CurY
MouseMove>CurX,CurY
Until>WW_Result=TRUE

//Adobe opened and the script continues past the repeat loop.
[/code]
We are on Windows Server 2012 and it is a server timeout. Does not work like a screensaver movement or at least during my testing they were timing out so I made the movement loop. Its about 30 seconds each cycle. Start qty 1000 = 8 hrs movement. It could proabably be streamlined with a better timer/clock, but wasn't sure how to get that working yet....

Had to test it so its still developemental phase:


//Let>IGNORESPACES=1
Wait>3
input>maxmoves,How many mouse movements
Wait>1
Let>r=0
Let>balance=%maxmoves%-%r%
Let>time=%maxmoves%*30
Let>minutes=%time%/60
Let>balhour=%minutes%/60
Let>k=0
//Time1 = minutes
Dialog>Dialogmouse
object Dialogmouse: TForm
Left = 255
Top = 150
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'Wait Time'
ClientHeight = 195
ClientWidth = 212
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
Position = poScreenCenter
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 56
Top = 0
Width = 70
Height = 13
Caption = 'Moving Mouse'
end
object Label2: TLabel
Left = 40
Top = 64
Width = 3
Height = 13
end
object Label3: TLabel
Left = 16
Top = 24
Width = 41
Height = 13
Caption = 'Start Qty'
end
object Label4: TLabel
Left = 16
Top = 64
Width = 28
Height = 13
Caption = 'Count'
end
object Label5: TLabel
Left = 16
Top = 104
Width = 39
Height = 13
Caption = 'Balance'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label6: TLabel
Left = 96
Top = 24
Width = 69
Height = 13
Caption = 'MousePosition'
end
object Label7: TLabel
Left = 96
Top = 80
Width = 76
Height = 13
Caption = 'Remaining Time'
end
object Label8: TLabel
Left = 104
Top = 104
Width = 17
Height = 13
Caption = 'Min'
end
object Label9: TLabel
Left = 152
Top = 104
Width = 23
Height = 13
Caption = 'Hour'
end
object Label10: TLabel
Left = 16
Top = 144
Width = 68
Height = 13
Caption = 'CycleSeconds'
end
object MSMemo1: tMSMemo
Left = 16
Top = 80
Width = 65
Height = 17
Lines.Strings = (
'MSMemo1')
TabOrder = 0
Text = 'MSMemo1'
end
object MSMemo2: tMSMemo
Left = 16
Top = 40
Width = 65
Height = 17
Lines.Strings = (
'MSMemo2')
TabOrder = 1
Text = 'MSMemo2'
end
object MSMemo3: tMSMemo
Left = 16
Top = 120
Width = 65
Height = 17
Lines.Strings = (
'MSMemo3')
TabOrder = 2
Text = 'MSMemo3'
end
object MSMemo4: tMSMemo
Left = 96
Top = 40
Width = 100
Height = 17
Lines.Strings = (
'MSMemo4')
TabOrder = 3
Text = 'MSMemo4'
end
object MSMemo5: tMSMemo
Left = 96
Top = 120
Width = 41
Height = 17
Lines.Strings = (
'MSMe'
'mo5')
TabOrder = 4
Text = 'MSMemo5'
end
object MSMemo6: tMSMemo
Left = 144
Top = 120
Width = 41
Height = 17
Lines.Strings = (
'MSMe'
'mo6')
TabOrder = 5
Text = 'MSMemo6'
end
object MSMemo7: tMSMemo
Left = 16
Top = 160
Width = 41
Height = 17
Lines.Strings = (
'MSMe'
'mo7')
TabOrder = 14
Text = 'MSMemo7'
end
end
EndDialog>Dialogmouse
MouseMove>120,700
GetCursorPos>X,Y
Show>Dialogmouse
SetDialogProperty>Dialogmouse,,Position,poDesigned
SetDialogProperty>Dialogmouse,,Left,700
SetDialogProperty>Dialogmouse,,Top,170
SetDialogProperty>Dialogmouse,MSMemo2,text,%maxmoves%
SetDialogProperty>Dialogmouse,MSMemo1,text,%r%
SetDialogProperty>Dialogmouse,MSMemo3,text,%balance%
SetDialogProperty>Dialogmouse,MSMemo4,text,%X%,%Y%
SetDialogProperty>Dialogmouse,MSMemo5,text,%minutes%
SetDialogProperty>Dialogmouse,MSMemo6,text,%balhour%
SetDialogProperty>Dialogmouse,MSMemo7,text,%k%
Repeat>r
//Let>r1=1
MouseMove>120,700
add>r,1
Let>r2=r-1
Show>Dialogmouse
Wait>5
Let>k=5
Show>Dialogmouse
SetDialogProperty>Dialogmouse,MSMemo4,text,%X%,%Y%
SetDialogProperty>Dialogmouse,MSMemo7,text,%k%
Wait>2
Let>k=7
SetDialogProperty>Dialogmouse,MSMemo7,text,%k%
LClick
Wait>3
Let>k=10
SetDialogProperty>Dialogmouse,MSMemo7,text,%k%
GetCursorPos>X,Y
Show>Dialogmouse
Wait>10
Let>k=20
SetDialogProperty>Dialogmouse,MSMemo7,text,%k%
MouseMove>{%X%+1},{%Y%+1}
GetCursorPos>X,Y
Show>Dialogmouse
SetDialogProperty>Dialogmouse,MSMemo4,text,%X%,%Y%
Wait>10
Let>k=30
SetDialogProperty>Dialogmouse,MSMemo7,text,%k%
GetCursorPos>X,Y
MouseMove>{%X%-1},{%Y%-1}
GetCursorPos>X,Y
SetDialogProperty>Dialogmouse,MSMemo4,text,%X%,%Y%
Let>balance=%maxmoves%-%r%
Let>balmin1=%balance%*30
Let>balmin=%balmin1%/60
Let>balhour=%balmin%/60
//MouseMoveRel>70,50
Show>Dialogmouse
SetDialogProperty>Dialogmouse,,Position,poDesigned
SetDialogProperty>Dialogmouse,,Left,700
SetDialogProperty>Dialogmouse,,Top,170
SetDialogProperty>Dialogmouse,MSMemo2,text,%maxmoves%
SetDialogProperty>Dialogmouse,MSMemo1,text,%r%
SetDialogProperty>Dialogmouse,MSMemo3,text,%balance%
SetDialogProperty>Dialogmouse,MSMemo4,text,%X%,%Y%
SetDialogProperty>Dialogmouse,MSMemo5,text,%balmin%
SetDialogProperty>Dialogmouse,MSMemo6,text,%balhour%
SetDialogProperty>Dialogmouse,MSMemo7,text,%k%
Until>r={%maxmoves%}
Just when you thought it was safe to go in the water........:evil:

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

Re: Repeat and use WaitWindowOpen for exit of loop

Post by JRL » Thu Jan 04, 2018 7:23 pm

If you want the "r" Repeat loop to end when the Adobe Acrobat window opens. Add the following four lines at the end of the loop. Of course if the loop takes 30 seconds the loop will not end for up to 30 seconds after the window opens.

You also need to have a WW_Timeout line somewhere in the script prior to the WaitWindowOpen> line.

Let>WW_Timeout=0.5

I made the value 0.5 but it can be any value you choose except 0 (zero). Making WW_Timeout value zero will cause the script to pause and wait until the window opens.

Code: Select all

WaitWindowOpen>Adobe Acrobat
If>WW_Result=True
  Let>r=maxmoves
EndIf

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