Application Selection using WinActivate + Regular Expressions for AutoHotkey

This is a brief adjunct to my post on using Autohotkey in Radiology (which basically every radiologist should be doing, by the way). I include it here not because I expect many people to run into the same problem I did but rather because it’s a good example of the not-so-challenging troubleshooting that we shouldn’t be scared to do in our quest for a better workflow. I’m a novice and that’s okay! We can still do cool stuff!

In that post, I mentioned an example script I made to streamline launching patient charts in Epic from PACS at home since our automatic integration doesn’t work remotely.

One thing I didn’t describe in that post is an annoying quirk for activating Epic because it runs through Citrix. Since Citrix is weird, and there are presumably multiple servers that can run Epic, the window title of our Epic actually changes with each login. Therefore, the usual static name-matching technique we use to activate Powerscribe, Chrome, or other typical apps doesn’t work.

In our system, Epic always has a title like “ecpprd2/prdapp01” or “ecpprd3/prdapp04”–but the numbers always shift around.

For a while, I used a workaround:

WinActivate, ahk_exe WFICA32.EXE

…which is the name of the Epic/Citrix program .exe file runningĀ  on my PC, and as long as only one Citrix application was open at the time, it worked (I had to make sure to close an MModal application that auto-launched with it, but otherwise it was fine). Recently, my hospital started using some useless AI tool that cannot be closed, which broke my script.

The workaround one of my colleagues figured out is to change the AHK TitleMatchMode of that specific hotkey to recognize “regular expressions” (a “RegEx” is a sequence of characters that specifies a pattern of text to match).

SetTitleMatchMode RegEx

Then we can use WinActivate with a few modifiers to recognize an unchanging portion of the window title. In our example above, where the title always contains ecpprd or prdapp, we can use the following to select the EPIC window:

WinActivate i)^ecpprd

In this example, the “i” modifier allows case-insensitive search, and the carat (^) limits the string to the beginning of the window title. You can read more about regular expressions in AKH here.

In reality, if I had just explained my problem to any of the popular LLMs, I’m confident they would have given me the answer. They absolutely excel at this. The rapidly approaching agentic era will allow for some very easy, very powerful scripting in the very near future even if commercial products lag behind.

Leave a Reply