MakaPakaTobyHannah Posted February 28, 2020 Report Share Posted February 28, 2020 This particular issue has plagued me for a very long time, and I just cannot figure out what the issue is. I find that "Window Activate" is extremely unreliable. Whenever I develop scripts where, after one thing is done in one window another window must be activated before the macro proceeds, the macro simply hangs. Today’s example. I wish to batch print to PDF all *.musx files in a given directory. For this to work, each *.musx files must first be opened, in turn. I have to: 1) Issue the open command to the first file in the list 2) Wait for the file to open 3) Issue a "print" command within the application (this will call Adobe Acrobat) 4) Wait for the PDF to have been compiled and open within Acrobat 5) Close the newly opened PDF 6) Reactivate the window of the original application 7) Close the file that was opened within that application 8) Continue on to the next file by looping back to step (1) There are various dialog boxes that come up (Open, Print, Save PDF File As). In order for the "open" and "close" commands (sent as keystrokes) within the main application to function properly, the main application must be active. Hence my use of the Window Activate command. I have experimented with "Exact Match," "Partial Match," "Partial Match" with "The name contains wildcards" checked and the use of the asterisk character. I have inserted delays in front and after the Window Activate commands. Sometimes it works, sometimes the macro hangs. Is this a known problem? Again, I have had trouble with this for so long, it’s not even funny. But today, I just cannot get this process to work reliably. I have hundreds of PDFs to compile, and I don’t want to do this manually one file at a time. MORE INFO I just inserted an "If Window is Running" check. I placed the window title precisely; instead of typing it, I populated the field by selecting the window title via "Browse". The "If Window is Running" check is supposed to open a text box saying, the window is running. But that text box doesn’t even come up. In other words, the If function doesn’t see the window, even though it is visible. Quote Link to comment Share on other sites More sharing options...
terrypin Posted February 28, 2020 Report Share Posted February 28, 2020 It's not what you want to hear, but over the years I too have found both Window Activate and Wait for Window Title unreliable. Some instances work, others don't. I can often instead use Delay commands (determined by trial/error). Sometimes I've had to resort to other methods, such as pixel colour recognition, slowing down that section with Macro Playback Speed, etc. This has been my experience over several versions of the OS, probably from 95 , 2000 and XP to Win 10. I assume some sort of timing conflict with the OS and/or other apps running simultaneously with the macro. Quote Link to comment Share on other sites More sharing options...
MakaPakaTobyHannah Posted February 28, 2020 Author Report Share Posted February 28, 2020 Grmpf. Thanks for that response, terrypin. At least I can see that I’m not the only one with this problem. I have never experimented with slowing down the macro, I'll try that now first. Very doubtful. Quote Link to comment Share on other sites More sharing options...
MakaPakaTobyHannah Posted February 28, 2020 Author Report Share Posted February 28, 2020 Further to this... a brute force approach. It’s interesting that some "wait for window" calls in this script function 100% reliably; the one activating the main application, however, fails more often than not. I agree, it must be how this application manages window titles. Be that as it may, I removed all calls for activating the main application window. Instead, as the macro is first called from within that application, with a scope set to that application, I use a left mouse click to click on the main application window, where needed. Now, the macro runs flawlessly. Saves a lot of tedious hassle... Quote Link to comment Share on other sites More sharing options...
rberq Posted February 28, 2020 Report Share Posted February 28, 2020 Echoing what terrypin said, I have never found Window Activate to be reliable. I was about to suggest finding some totally different way of doing the activation, but I see you have already done exactly that. Congratulations. Must be an immense relief after all that frustration.🙂 Quote Link to comment Share on other sites More sharing options...
Samrae Posted February 28, 2020 Report Share Posted February 28, 2020 I have found Window Activate and Wait for Window Title work well for the main window of an application but not always for dialogs that the application might pop up. Quote Link to comment Share on other sites More sharing options...
MakaPakaTobyHannah Posted February 28, 2020 Author Report Share Posted February 28, 2020 Thanks for all the feedback. Anybody written to MacroExpress about this? I will now; I have found them to be very responsive. I think this is a serious limitation, and really wastes a lot of time. Quote Link to comment Share on other sites More sharing options...
Pete Posted March 2, 2020 Report Share Posted March 2, 2020 With reference to the original problem of printing multiple .PDF files. You should be able to launch acrobat from the command line with parameters for the specific file, and to print to a specific printer. This might reduce the amount of window manipulation that needs to be done by MEx? https://stackoverflow.com/questions/619158/adobe-reader-command-line-reference There is also a utility which may help you here - http://www.columbia.edu/~em36/pdftoprinter.html I haven't looked at these options in any depth, but you may want to explore further. Quote Link to comment Share on other sites More sharing options...
Cory Posted March 3, 2020 Report Share Posted March 3, 2020 I remember using A-PDF for many massive operations with MEP. Many good command line options. Free and/or cheap. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.