Jump to content

When is it safe to close a window?


Recommended Posts

I wrote a script to print all attachments in a selected Thunderbird email. It USUALLY works ok but sometimes it misses a file or two. I think it's because of timing but I'm not sure of the best way to handle it. I copy all the attachments to a temp folder then loop through the files. Based upon extension, I RUN the associated app and then send a CTRL-P{ENTER} to print it. The problem is, I think I close the window before the printing actually is done. How can I determine when it's safe to close the window (application)? Here's a sample section of my code:

Run('"C:\Program Files\WordPerfect Office 12\Programs\wpwin12.exe" "' & $fpath & $file & '"') ;start the appropriate app based upon filetype
WinWaitActive($file) ;wait for the app window to come up
Send('^p{enter}') ;print the document
WinWaitActive($file) ;in case there was an intervening PRINT dialog notice that popped up, wait for the main app to re-appear.
Sleep(1000) ;wait an arbitrary amount of time for things to settle down (too much? - too little?)
WinClose($file) ;close the application and then loop back for another file to print
Link to comment
Share on other sites

Because your working with different types of files maybe one of the option that you can consider to try is PixelChecksum() 'with coordinates of win that is opened for printing' before you send print keyes, put some sleep like you already did, and try to compare it in some loop until you get = PixelChecksum()

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Try using the winwait("Print") command. All of the windows I tried had the same name for the window so basically

Send("^p")
winwait("Print")
Send("{enter}")
Sleep(500)

Think that should do it... but if not just add some extra clauses depending on the print window dialog. Pixelchecksum() also works and I would probably use that if this way doesnt work for ya.

Good luck

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...