TitleWait is a program automation and testing tool (currently just for Windows, tested on XP through Windows8). It can be used to launch a program and then watches for optional conditions to close the program...most notably when the title of the window changes to match a regular expression. It also provides graceful recovery and detection of crashes, and can take screen shapshots when detected conditions arise.
It should show no output in the console, and only pop up Notepad for a second and shut it down. Afterward, test.bmp should contain a screenshot of Notepad before it was closed.
You can then use TitleWait to watch for the appearance of this string as part of the title bar of any of your windows. Browsers generally add their own text, but will always have the page title as a part of the title bar. You can use regular expressions to define the condition
Thus, using no other interprocess communication methods, it's possible to use the title to "signal" this small program that a certain condition has been reached. It will not terminate until that happens, unless you specify a timeout. As an added bonus, TitleWait can take screen snapshots of the application's window or the whole screen in the case of a crash, timeout, or title match. You can also set the position of the launched process's window on the screen.
Options are given with two dashes, a word, and an equals sign. So for instance --verbose=1 or --program="foo.exe".
For all options that are strings, enclose them in quotes. To embed quotes in those strings, use \".
3 => No program to run was supplied with --program
4 => A timeout was specified and program didn't exit before timeout
5 => Attempt to close the window normally failed, had to terminate
6 => The spawned process crashed
7 => The spawned process closed itself before match or timeout
8 => Running with --defer option and user canceled instead of waiting
I'd be very interested to know if someone could reproduce these results using AutoHotkey (GPL) or AutoIt (free, closed), which I found out about a couple years later. Though I'd suspect they wouldn't handle some of these cases.
What is tricky in particular is the graceful handling of dealing with programs that are implemented in terms of a launcher and child processes, such as many browsers today. Being a debugger makes it easier to stay in the driver's seat and get notifications as processes and threads are started and stopped. So even if you called a program that launched and returned to the shell immediately (like IEXPLORE.EXE), a script using TitleWait can hold up until the processes doing the real work have all actually exited.
In any case, the source code was published in 2013 "in the hope that it might be useful". GPLv3 license.
I don't like programming to flat Win32 API any more than anyone else does, but it simplifies the dependency structures. I can't count the number of dumb little utilities like this I've downloaded which have one simple function but then won't run because they're missing a DLL or something.
Copyright (c) 2007-2018 hostilefork.com
Project names and graphic designs are All Rights Reserved, unless otherwise noted. Software codebases are governed by licenses included in their distributions. Posts on blog.hostilefork.com
are licensed under the Creative Commons BY-NC-SA 4.0 license, and may be excerpted or adapted under the terms of that license for noncommercial purposes.