When starting an application with Run Program use RP_WAIT=2 to tell it to wait until the application is ready for input before continuing. You can wait for pixel colors to change, mouse cursors and windows to change, detect object captions and wait for files, and portions of the screen to change amongst other things. There are ways to wait for all sorts of other events to take place too, some more advanced than others. Use WaitWindowClosed after issuing a command that causes the window to close. This will ensure the script waits for that window to appear before continuing. Always use WaitWindowOpen after running a program or sending an event that causes a new window to appear. A script isn’t quite so clever and unless you tell it to wait for certain actions to complete it will blindly move on to the next step. Also remember that when you do something manually you will subconsciously wait for the outcome of each action. The process may take longer on another occasion and fail. Try not to use absolute wait times to wait for events to complete. So it’s a good habit to get into to use SetFocus before sending a set of keystrokes. When you start a program it nearly always becomes the active window, but other applications can steal the focus. Get into the habit of using SetFocus even after running a program with the Run Program command. So you need to make sure the window you want the keystrokes to land in is the active window. When you do that the keystrokes land on the active window. Use SetFocus! When sending keystrokes Macro Scheduler just simulates what you do when you press keys on the keyboard. You can also use the debugger to step through the script line by line. Building the script up in this way will iron out issues as you go rather than leaving you desperately trying to hunt down the cause of an error amongst one long script. Run it and make sure the process ends up where you expected. write the code that opens the app, waits for it to be active and sends the first keystroke. Start by just scripting the first few steps. Don’t try to write the whole thing at once. I find it is best to break the script down into manageable chunks. This list will translate well into a Macro Scheduler script. You’ll end up with a list of keystrokes and window titles. Try to determine what indicates the completion of each step. Make a note of the keys you press, note down the title of each new window and how long each step takes. If you’re using the mouse excessively try to find keyboard alternatives. Run through the full process several times and find the simplest path. The most important thing before attempting to write a routine to automate a software process is to be familiar with the process itself. While I’m, writing this with our Windows Automation tool, Macro Scheduler, in mind, these tips will be appropriate whichever automation tool you are using. These are my tips for getting started with writing an automation script.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |