Findwindowwithtext

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
mmichalik
Newbie
Posts: 4
Joined: Mon Mar 27, 2006 11:44 am

Findwindowwithtext

Post by mmichalik » Mon Mar 27, 2006 12:04 pm

:?: On a server I have 4 open programs running on a server each displaying logs. When a log reports an error I would like to email a warning message.

I have tried the follwing script.



Let>SENDMAIL_STATUS=1
Let>subject=Test server failure
Let>me=[email protected]
Let>myname=Test Server
Let>recipients=[email protected]
Let>body=End of communications channel on test server
Let>mailserver=xxx
Let>CheckText=**Error
FindWindowWithText>CheckText,0,windowname,0
if>windowname=NOT FOUND,ENDLABEL
SMTPSendMail>recipients,mailserver,me,myname,subject,body,
Message>Result of SendMail: %SMTP_RESULT%
LABEL>ENDLABEL



No window is found with the "**Error" message, even though one was displaying the details.
I tried the same on PC with **Error typed into a word document and again this is not found, Does the Findwindowwithtext function work?

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 Mar 27, 2006 12:31 pm

Does the Findwindowwithtext function work?
Yes, but it doesn't necessarily work with every conceivable text object that exists. It may not be suitable for the window you are trying it with.

Are you able to copy the contents of the log window to the clipboard? If so one workaround is to automate that and use GetClipBoard to get the text into a script variable.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

mmichalik
Newbie
Posts: 4
Joined: Mon Mar 27, 2006 11:44 am

Using Clipborad

Post by mmichalik » Mon Mar 27, 2006 1:16 pm

Thanks for the quick reply.

I don't have access to the four programs that are running, other than monitoring their output, so I don't see how I could use the copy to clipboard. The log files these programs produce constantly scrolls the log of the days work and only stops when an Error is thrown.

The idea is to run the macro half hourly to inform me if any of the four screens shows an error i.e. the process has stopped.

The screens scroll the text in a standard VB text box.

I have tried pasting the **Error into notepad and leaving this visible. The macro still fails to pick up the Notepad window.

I am using Macro Scheduler version 6.2.3.

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 Mar 27, 2006 1:21 pm

The screens scroll the text in a standard VB text box.
In that case, you should be able to have the macro do a CTRL-A on thet text box, to highlight it all, and then a CTRL-V to copy the contents to the clipboard. If it is a standard VB text box then you will be able to do that. If you can copy the text from it manually, then you can make the macro do it to.

The macro could do this for each log window when ever it runs and then use GetClipBoard to get that data into a clipboard variable. Then it just needs to scan that variable for the occurence of whatever indicates an error.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

mmichalik
Newbie
Posts: 4
Joined: Mon Mar 27, 2006 11:44 am

Post by mmichalik » Mon Mar 27, 2006 2:46 pm

The problem I have is that the text box could be 65532 characters long
so it could take some time...

I did this with a notepad open with "Got text" in it,
it sets focus on the notepad but it fails to highlight and copy the text?
I would still prefer the findwindowwithtext rather than opening the 4 screens. The problem I have is the debugging causes problems for obvious reasons.


SetFocus>Untitled - Notepad*
wait>3
Press ctrl
Send>A
wait>2
Send>C
wait>5
release ctrl
GetClipBoard>CheckText
Pos>"Got text",CheckText,1,TestFortext
IF>TestFortext=0,ENDLABEL


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 Mar 27, 2006 2:51 pm

Hi,

I'm afraid FindWindowWithText can only retrieve text that is retrievable - that Windows and Applications make available.

Always use lower case characters when sending them with modifier keys. Your Notepad script should be:

Setfocus>Untitled - Notepad*
Press CTRL
Send>a
Release CTRL
Press CTRL
Send>c
Release CTRL
WaitClipBoard
Wait>2
GetClipBoard>checkText

If there is lots of text going on to the clipboard you will need a way to wait between the CTRL-c and the GetClipboard so that the script allows time for the data to be on the clipboard.

One way to do this instead of a static wait is to use a loop:

PutClipboard>NOTHING
Press CTRL
Send>c
Release CTRL
Label>waitclipboard
Wait>0.5
GetClipBoard>data
If>data=NOTHING,waitclipboard


So what this does is prime the clipboard with a known value, then do the CTRL-c and then loop until the clipboard data is no longer the known value.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

mmichalik
Newbie
Posts: 4
Joined: Mon Mar 27, 2006 11:44 am

Post by mmichalik » Mon Mar 27, 2006 3:03 pm

:) Thanks I will try using this method

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