 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
grymoire
Joined: 15 Jun 2009 Posts: 4
|
Posted: Mon Jun 15, 2009 10:54 pm Post subject: WinWait woes |
|
|
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! |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Tue Jun 16, 2009 4:45 pm Post subject: |
|
|
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
} |
|
|
| Back to top |
|
 |
grymoire
Joined: 15 Jun 2009 Posts: 4
|
Posted: Tue Jun 16, 2009 6:28 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
JDN
Joined: 24 Mar 2004 Posts: 299
|
Posted: Tue Jun 16, 2009 8:59 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Tue Jun 16, 2009 9:31 pm Post subject: |
|
|
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. _________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
grymoire
Joined: 15 Jun 2009 Posts: 4
|
Posted: Wed Jun 17, 2009 9:45 pm Post subject: |
|
|
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!!! |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Thu Jun 18, 2009 2:58 am Post subject: |
|
|
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
} |
|
|
| Back to top |
|
 |
grymoire
Joined: 15 Jun 2009 Posts: 4
|
Posted: Thu Jun 18, 2009 4:27 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|