AutoHotkey Community

It is currently May 26th, 2012, 6:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: WinWait woes
PostPosted: June 15th, 2009, 11:54 pm 
Offline

Joined: June 15th, 2009, 11:10 pm
Posts: 4
I'm trying to launch two Acrobat viewer windows with two different files and send some commands to each. WinWait Seems to timeout after the second launch even though it appears to have succeeded.

I've tried many variants but one of the cleanest is below.

Any ideas?

Code:
#NoEnv
SendMode, Input
ViewerApp=C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

#t::
Launch("file1.pdf")
Launch("file2.pdf")
return

Launch( File )
{
  global ViewerApp

  Run, %ViewerApp% %File%,,UseErrorLevel,thePID
  if ErrorLevel
  {
    MsgBox Failed to launch the viewer!`n%ViewerApp%`nErrorLevel = %ErrorLevel%
    return
  }
  WinWait, ahk_pid %thePID%,,30
  if ErrorLevel
  {
    Exists = Window for process %thePID% does not exist.
    IfWinExist, ahk_pid %thePID%
      Exists = Window for process %thePID% does indeed exist.
    MsgBox Failed to launch the viewer!`n%ViewerApp%`n%File%`nErrorLevel = %ErrorLevel%`n%Exists%
    return
  }
  ; do some things with the window
  WinActivate, ahk_pid %thePID%
  WinRestore,  ahk_pid %thePID%
  WinMaximize, ahk_pid %thePID%
  Send !vzp ; set zoom level
}



Thanks to anyone who can help!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2009, 5:45 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
This little script seems to work fine for me (I ran it a couple times).
Code:
Loop,2 {
 Run, File%A_Index%.pdf,,Max
 WinWaitActive, File%A_Index%.pdf,,3
 If !ErrorLevel
  Send !vzp
 Else MsgBox, Error launching File%A_Index%.pdf
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2009, 7:28 pm 
Offline

Joined: June 15th, 2009, 11:10 pm
Posts: 4
Thanks for the reply.

I tried the snippet you suggest but I get error dialogs for BOTH files now even though the windows do appear. I get the same behavior if I bump the timeout from 3 to 30 seconds.

BTW, the original script seemed to work for me on my faster Vista box at home. My machine here (where it's not working) is a slower XP box. I'm not sure what the difference would be or how to adjust for it.

Other ideas?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2009, 9:59 pm 
Offline

Joined: March 24th, 2004, 2:34 pm
Posts: 299
I have had quite a few problems with Winwait and I'm curious about one thing in this line:

Code:
WinWait, ahk_pid %thePID%,,30


Why is there no comma between the "ahk_pid" and %thePID%?

I almost always use the expression style and so if this is something unique to the traditional style, then I probably don't understand why it's OK to omit the comma.

But when using WinWait in the expression style, there must be commas separating the parameters. Also, it seems to me you are using both Wintitle and Wintext to terminate the WinWait command. If you are not getting it to terminate, why not try to use only one of them? In most cases, woudln't that get Winwait to terminate sooner?

Almost all the problems I've ever had with Winwait had to do with trying to specify both WinTitle and WinText. Usually it's because WinText can change very easily in several different circumstances.

So, I would try to use the expression method instead of the Traditional method and I would also try using just WinTitle instead of both WinTitle and WinText. If that doesn't work, perhaps you could omit WinTitle and just try WinText?

In any event, I would check the variable %thePID% to make sure it has the value that you expect it should have at the time the WinWait command is executed. Most of my problems with WinWait have been that that variable has changed value unexpectedly and contains a value that does not get WinWait to terminate correctly.

Good luck.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2009, 10:31 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I have no clue how your function is supposed to accomplish what you're asking of it (part of that may be the strange formatting when you posted your code). Could you please add some comments so it's a little easier to understand?


JDN wrote:
Code:
WinWait, ahk_pid %thePID%,,30


Why is there no comma between the "ahk_pid" and %thePID%?

I almost always use the expression style and so if this is something unique to the traditional style, then I probably don't understand why it's OK to omit the comma.


A comma isn't needed between those two things, they designate what window WinWait is waiting for (using the process's ID). The format is just like using ahk_class IEFrame. The WinTitle can't be an expression, so it has to stay in "traditional" mode and since the process ID is saved to a variable it has to be put into that format.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2009, 10:45 pm 
Offline

Joined: June 15th, 2009, 11:10 pm
Posts: 4
I will try again to be as clear as I can about my problem. The simplified example below (from jaco0646) does not work for me.

Expected result: Script should successively launch the two files (file1.pdf and file2.pdf) in two pdf browser windows (Adobe Reader on my system). WinWaitActive (or WinWait in the original example) should not time out or set the ErrorLevel (ie. it should succeed).

Actual result: Both files launch in Adobe Reader as expected but WinWaitActive (or WinWait) times out and sets the error level resulting in the error dialog.

Code:
Loop,2 {
 Run, File%A_Index%.pdf,,Max
 WinWaitActive, File%A_Index%.pdf,,30
 If !ErrorLevel
  Send !vzp
 Else MsgBox, Error launching File%A_Index%.pdf
}


I understand that this appears to work on some machines, but I have several machines here (all WinXP) where it does not work.

Any help in understanding why this might be the case would be greatly appreciated.

Thanks!!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2009, 3:58 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Just a guess: maybe SetTitleMatchMode,2 would help.
Code:
SetTitleMatchMode,2
Loop,2 {
 Run, File%A_Index%.pdf,,Max
 WinWaitActive, File%A_Index%.pdf,,30
 If !ErrorLevel
  Send !vzp
 Else MsgBox, Error launching File%A_Index%.pdf
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2009, 5:27 pm 
Offline

Joined: June 15th, 2009, 11:10 pm
Posts: 4
:( Sadly, "SetTitleMode,2" did not make a difference.
:) Happily, I discovered something that did.

By default, Acrobat does not create a separate instance/process for the second launch of Acrobat. I don't grok this fully yet, but this appears to be why winwait is failing on the second launch. Adding a "/n" switch to the Acrobat command line forces the launch of a new instance and appears to solve my problem.

Thanks for your help!
-Grym


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], dra, rbrtryn and 65 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group