WaitScreenImage more than once

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
minchia
Newbie
Posts: 14
Joined: Tue Apr 28, 2009 8:33 am

WaitScreenImage more than once

Post by minchia » Tue Apr 28, 2009 8:41 am

Hi All, relatively new to this, so please bare with me.

i'm trying to write a macro that will open outlook files from a DB and save them individually. i can do the bulk of it, but am stuck.

i'm using screencapture to wait for a certain symbol to come onto the screen, then i hit save as and go from there. I need to use the WaitScreenImage to search for this symbol, but the problem is that the symbol may be different depending on the type of MSG file that is open.

i want to have something like

WaitScreenImage>c:\image1.bmp
or
WaitScreenImage>c:\image2.bmp
save as function

does anyone know if this is possible?
i've added the code below.

many thanks

Arthur
----------------------

Let>k=1
Label>start
ReadLn>c:\\\MsgAttachmentIDs.txt,k,line
StringReplace>line, ,,tmpline
If>line=##EOF##,finish
run>C:\OpenMsgAttachment.exe %tmpline
wait>0.3
sent ALT + o

WaitScreenImage>C:\PP5\OpenMsgAttachment\button.bmp,20

PRESS ALT
send>fa
release ALT

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Tue Apr 28, 2009 9:57 am

Here's how I do it with finding a position you could probably adapt this easily:

Code: Select all

Let>XPFound=0
Let>VISTAFound=0
FindImagePos>%Script_dir%/taskxp.bmp,SCREEN,50,1,X,Y,XPFound
FindImagePos>%Script_dir%/taskvista.bmp,SCREEN,50,1,X,Y,VISTAFound

If>{(%XPFound% > 0) OR (%VISTAFound% > 0)}
  MouseMove>X_0,Y_0
  // This is what happens if one of the images is found
Else
  GOTO>Exit
  // This is what happens if none of the images is found
Endif
Phil Pendlebury - Linktree

minchia
Newbie
Posts: 14
Joined: Tue Apr 28, 2009 8:33 am

Post by minchia » Tue Apr 28, 2009 11:23 am

thanks for that, looks like it should work. i'll give it a go and see.

minchia
Newbie
Posts: 14
Joined: Tue Apr 28, 2009 8:33 am

Post by minchia » Wed Apr 29, 2009 1:02 am

i've tried the above a few times, and it seems to keep failing in the if statement. i think it may be due to the image it's looking for not being in the screen at the time of the if statement. i was using the WaitScreenImage because the time it take for the screen to come up varies and is not always a fixed time. i think to fix this i can add in a Wait cmd, but i don't want to do that as it will eat up time.

any help is appreciated.

Code: Select all

run>C:\Conversions\OpenMsgAttachment\OpenMsgAttachment.exe %tmpline%
wait>0.3
sent ALT + o

FindImagePos>C:\PP5\OpenMsgAttachment\button.bmp,SCREEN,0,1,X,Y,NumFound
FindImagePos>C:\PP5\OpenMsgAttachment\button2.bmp,SCREEN,0,1,X,Y,NumFound2

if>{(%numfound% > 0) OR (%numfound2% > 0)}
    PRESS ALT
    send>fa
    release ALT
else
    MessageModal>Fail!!
endif

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Apr 29, 2009 1:37 am

Does it work without the space chars?
Change from:
if>{(%numfound% > 0) OR (%numfound2% > 0)}

Change To:
if>{(%numfound%>0) OR (%numfound2%>0)}
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

minchia
Newbie
Posts: 14
Joined: Tue Apr 28, 2009 8:33 am

Post by minchia » Wed Apr 29, 2009 2:31 am

thanks bob, unfortunately that didn't make a difference, i'm now trying to use the below method, althou, i still have to have a specific wait time, which i can't really have. The time it takes after i hit ALT+o varies between 5 and 10.

Code: Select all

Let>WSI_TIMEOUT=4
run>C:\Conversions\OpenMsgAttachment\OpenMsgAttachment.exe %tmpline%
WaitScreenImage>C:\PP5\OpenMsgAttachment\MsgProg.bmp,20
send> ALT + o

WaitScreenImage>C:\PP5\OpenMsgAttachment\button.bmp,20
//WaitScreenImage>C:\PP5\OpenMsgAttachment\button2.bmp,20

If>WSI_TIMEDOUT=FALSE
MessageModal>Normal
else
MessageModal>Undeliverable
endif
Let>k=k+1
Goto>start

label>finish
MessageModal>Finsihed.
Exit>0

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Increase WSI_TIMEOUT, WaitWindowOpen, SetFocus

Post by gdyvig » Wed Apr 29, 2009 2:55 am

Try setting WSI_TIMEOUT to a value well over the usual range of 5-10.

Code: Select all

Let>WSI_TIMEOUT=20
//Will wait only 5 seconds if image is found in 5 seconds.
Unfortunately it will wait the full 20 seconds if you look for the notfound image first. So look for both images simultaneously using a repeat loop:

Code: Select all

Let>WSI_TIMEOUT=1
Let>counter=0
Repeat>counter

  WaitScreenImage>C:\PP5\OpenMsgAttachment \button.bmp,20
  if>WSI_TIMEDOUT=TRUE
    WaitScreenImage>C:\PP5\OpenMsgAttachment\button2.bmp,20
  endif

 
  if>WSI_TIMEDOUT=FALSE
    //found image, exit loop
    Let>counter=10
  else
    Let>counter=counter+1
  endif

Until>counter=10
Also make sure you are setting focus on the window you wish to accept the key stroke. If the image is in that window:

Code: Select all

//Wait until image is found using WaitScreenImage
//Find image using FindImagePos
MouseMove>X_0,Y_0
LClick
//Send the keystrokes
Or do it this way:

Code: Select all

//Wait until image is found using WaitScreenImage
SetFocus>MyWindow
//Send the keystrokes

Try incorporating these suggestions into our script and let us know if that solves it.

Gale

minchia
Newbie
Posts: 14
Joined: Tue Apr 28, 2009 8:33 am

Post by minchia » Wed Apr 29, 2009 5:47 am

Thanks Gale and to everyone else who responded. The above seems to have done the trick. I'll re-post if i'm still battling.

minchia
Newbie
Posts: 14
Joined: Tue Apr 28, 2009 8:33 am

Post by minchia » Thu Apr 30, 2009 5:04 am

The above helped immensely. Problem solved, thanks everyone.

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