A while ago I wrote an ahk script that toggles open a dictionary text file which is used to improve the pronunciation abilities of a text-to-speech program that I use. The same key combo opens the file for changes, saves the edits and closes the file.

The lingering problem was that often, the script would close down whatever the active window was, instead of opening the txt file like it was meant to.

The fix (so far) is working, and was simple enough to add. It meant putting a WinWaitActive line just after the Run command, as shown in the script.

keywait, #numpad9
if toggle := !toggle
Run, “C:\box\docs\ReadPlease-words.txt”
WinWaitActive, ReadPlease-words.txt - metapad
Send ^s
send, !{F4}

Now, not only does the script save some bother when open/closing a file, it doesn’t make its own trouble either.

Hope you like.