Jump to content
Sign in to follow this  
markomc

AutoIt doesn't notice window closing

Recommended Posts

I've got stuck on what is my simplest script so far (and I have been having a lot of fun with AutoIt).

This script attaches a document to a blank email, fills in a bit of text and then waits for the user to click 'Send' on the Outlook menu. This script gets to the 'Please see attached part' (line 5) - so far so good.

Then the script pauses and never comes back; as you can see from the rem'd out line, I tried WinWaitClose to start with and then I tried a While...Wend to check for the existence of the window. However, when the user clicks on Send and closes the Outlook new mail window, the script stays paused and I never see the MsgBox.

I get the horrible feeling it's something obvious and I've even tried a separate GUI with an event button/function to get past this point but without success.

Any help would be greatly appreciated.

Regards,

Buzz

WinWait("See Attached - Message (HTML) ","")

If Not WinActive("See Attached - Message (HTML) ","") Then WinActivate("See Attached statement - Message (HTML) ","")

WinWaitActive("See Attached - Message (HTML) ","")

Send("{ENTER}Please see attached.{ENTER}{ENTER}Bye bye")

; WinWaitClose ("See Attached - Message (HTML) ","")

$i = 1

While $i = 1

If WinExists("Attached statement - Message (HTML)") Then

$i = 1

Sleep(1000)

Else

$i = 0

EndIf

WEnd

MsgBox (0, "supposed to be", "waiting for 'See Attached - Message (HTML) ' to close")

Share this post


Link to post
Share on other sites

I get the horrible feeling it's something obvious and I've even tried a separate GUI with an event button/function to get past this point but without success.

<{POST_SNAPBACK}>

Don't see anything really wrong with the code....

The WinWaitClose() should work ...

You are sure that the Send() is done ...right and that the script gets past line 3 ?

What are the OPT() settings you have in the script ?


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

One quick thing I thought of (not sure it matters to you but), If you have more than one message open then technically it will never close because there will be multiple ones open. Just something to think about.

Edit: Also is this the full script? Seems to me like there would be more to it.

JS

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Don't see anything really wrong with the code....

The WinWaitClose() should work ...

You are sure that the Send() is done ...right and that the script gets past line 3  ?

What are the OPT() settings you have in the script ?

<{POST_SNAPBACK}>

Thanks for your help.

The send(text) appears in the Outlook window so I know it gets past line 3.

The OPT settings are as follows:

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

AutoItSetOption("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=...

AutoItSetOption("WinSearchChildren", 1) ;0=no, 1=search children also

Regards

Buzz

Share this post


Link to post
Share on other sites

You are using "See Attached - Message (HTML) " in some places and "See Attached statement - Message (HTML) " in others.

<{POST_SNAPBACK}>

Thanks for pointing that out.

It's just a typo where I transposed the original and simplified it.

Buzz

Share this post


Link to post
Share on other sites

One quick thing I thought of (not sure it matters to you but), If you have more than one message open then technically it will never close because there will be multiple ones open. Just something to think about.

Edit: Also is this the full script? Seems to me like there would be more to it.

JS

<{POST_SNAPBACK}>

Thanks for replying.

There isn't anything else open that AutoIt is responsible for - in fact I'm waiting for the MsgBox to open.

I grabbed the relevant window title (for the WinWaitClose ("Untitled - Message (HTML) statement) using the AutoIt window info tool.

There is a bit more to the script but as I say, it's really pretty simple; I just posted the bit where it all seems to hang.

Regards

Buzz

Share this post


Link to post
Share on other sites

Thanks for your help.

The send(text) appears in the Outlook window so I know it gets past line 3.

The OPT settings are as follows:

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

AutoItSetOption("WinTitleMatchMode", 2)    ;1=start, 2=subStr, 3=exact, 4=...

AutoItSetOption("WinSearchChildren", 1)    ;0=no, 1=search children also

Regards

Buzz

<{POST_SNAPBACK}>

One thing I noticed about this set of options. You have the WinTitleMatchMode as 2 different settings. Unless you have those spaced out in your script that may be a conflict of some sort.

Why do you have it set twice?

That is all I can think of for now.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

I had this same problem today. I had to put a Sleep state after a WinWaitClose command to make it work 100% of the time. Shouldn't have to do this I suppose, and I don't understand it, but it worked for me. You might give it a try and see if it helps. Just an idea...

Share this post


Link to post
Share on other sites

One thing I noticed about this set of options. You have the WinTitleMatchMode as 2 different settings. Unless you have those spaced out in your script that may be a conflict of some sort.

Why do you have it set twice?

That is all I can think of for now.

JS

<{POST_SNAPBACK}>

Good point, I've tidied that up - in fact I've set it to exact mode because I thought AutoIt was seeing some other windows with part of the string in the title.

I also put the following routine in at the critical juncture, i.e.

$i = 0

Do

Sleep(500)

MsgBox (0, "thinks Attached statement - Message (HTML)", "$i is 1 if it exists: ... " & $i)

If WinExists("Attached statement - Message (HTML) ","") Then

$i = 1

Else

$i = 0

EndIf

MsgBox (0, "thinks Attached statement - Message (HTML)", "$i is 1 if it exists: ... " & $i)

Until $i = 0

MsgBox (0, "supposed to be", "waiting for 'attached statement' to close")

This continues to show $i equal to 1 even though the "Attached statement ..." window has been closed (manually by me); in other words, AutoIt is oblivious of the state of the window. I never get out of the Do... Until loop and never get to the third MsgBox.

Is there maybe another way to make AutoIt go and look for the window so that it realises it's not there anymore?

Baffled

Buzz

Share this post


Link to post
Share on other sites

Good point, I've tidied that up - in fact I've set it to exact mode because I thought AutoIt was seeing some other windows with part of the string in the title.

I also put the following routine in at the critical juncture, i.e.

$i = 0

Do

Sleep(500)

MsgBox (0, "thinks Attached statement - Message (HTML)", "$i is 1 if it exists: ... " & $i)

If WinExists("Attached statement - Message (HTML) ","") Then

$i = 1

Else

$i = 0

EndIf

MsgBox (0, "thinks Attached statement - Message (HTML)", "$i is 1 if it exists: ... " & $i)

Until $i = 0

MsgBox (0, "supposed to be", "waiting for 'attached statement' to close")

This continues to show $i equal to 1 even though the "Attached statement ..." window has been closed (manually by me); in other words, AutoIt is oblivious of the state of the window.  I never get out of the Do... Until loop and never get to the third MsgBox.

Is there maybe another way to make AutoIt go and look for the window so that it realises it's not there anymore?

Baffled

Buzz

<{POST_SNAPBACK}>

Have you tried running this code without a window open to see if you get the third message box?

I pulled the following from the help file...

Pauses execution of the script until the requested window does not exist.

WinWaitClose ( "title" [, "text" [, timeout]] )

Then there would be no need for the loop. It would create its own.

Here is some sample code also from the help file.

;Wait for the window "Untitled" to not exist
WinWaitClose("Untitled")

;Wait a maximum of 5 seconds for "Untitled" to not exist
WinWaitClose("Untitled", "", 5)

I hope that works for you. Let me know if I can do anything else.

Thanks,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Have you tried running this code without a window open to see if you get the third message box?

I pulled the following from the help file...

Then there would be no need for the loop. It would create its own.

Here is some sample code also from the help file.

;Wait for the window "Untitled" to not exist
WinWaitClose("Untitled")

;Wait a maximum of 5 seconds for "Untitled" to not exist
WinWaitClose("Untitled", "", 5)

I hope that works for you. Let me know if I can do anything else.

Thanks,

JS

<{POST_SNAPBACK}>

Hi, Thanks for your help.

I've tried using WinWaitClose already - I only tried using loops to see if I could make AutoIt notice that the window had closed.

I've attached the whole script; basically, it never gets to the last MsgBox but stays paused forever even after you have closed the Outlook window.

Still baffled

Buzz

Mailto_script.txt

Share this post


Link to post
Share on other sites

Hi, Thanks for your help.

I've tried using WinWaitClose already - I only tried using loops to see if I could make AutoIt notice that the window had closed.

I've attached the whole script; basically, it never gets to the last MsgBox but stays paused forever even after you have closed the Outlook window.

Still baffled

Buzz

<{POST_SNAPBACK}>

When I get home from work this evening I will give it a shot. See if I can recreate your situation and come up with a full solution for you.

I hope I will be of some service.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

When I get home from work this evening I will give it a shot. See if I can recreate your situation and come up with a full solution for you.

I hope I will be of some service.

JS

<{POST_SNAPBACK}>

Thank you very much for your help.

There is one other thing I've noticed when I tried another experiment with WinWaitClose, i.e. I inserted these lines at the end:

MsgBox (0, "supposed to be", "waiting for 'attached statement' to close")

WinClose($handle_f)

WinWaitClose ($handle_f, "")

I see the MsgBox and the window is closed by the WinClose command (the Do you want to save changes? dialog appears to which I respond No) and AutoIt still pauses forever. (You notice I'm now using handles as well!)

There must be something about WinWaitClose which I have misunderstood.

Going bonkers

Buzz

Share this post


Link to post
Share on other sites

Thank you very much for your help.

There is one other thing I've noticed when I tried another experiment with WinWaitClose, i.e. I inserted these lines at the end:

MsgBox (0, "supposed to be", "waiting for 'attached statement' to close")

WinClose($handle_f)

WinWaitClose ($handle_f, "")

I see the MsgBox and the window is closed by the WinClose command (the Do you want to save changes? dialog appears to which I respond No) and AutoIt still pauses forever.  (You notice I'm now using handles as well!)

There must be something about WinWaitClose which I have misunderstood.

Going bonkers

Buzz

<{POST_SNAPBACK}>

I'm not sure why this works but it solved the problem - I substituted these lines at the end for the WinWaitClose routine:

If WinExists ($handle_f) Then

WinWaitClose ($handle_f, "")

Else

EndIf

Note these are not in a loop but AutoIt does idle while the user enters stuff in the Outlook window, it notices when the Outlook window gets closed (or user sends email) and it proceeds correctly with the lines following the EndIf.

This problem seems peculiar to Outlook or something I am doing with Outlook; I've experimented with other apps and WinWaitClose works fine with them.

Thanks for your help - I hope this message gets to you before you spend any more time on the issue; I think I must have spent longer on this than all my other scripts put together!

Best regards

Buzz

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...