1
votes

AHK noob here. I'm looking to monitor 1-4 programs which run minimised for a specific change to the window title using autohotkey. When the change is detected in any of the programs, an alert pops up to alert the user of the change or the script could bring the program to the front.

The change in the window title (extracted using the AutoIt Spy tool) is from:

Lab - [Workspace... after this point the title text is dynamic

to either:

Lab - [Results ...etc

or simply

WARNING

The 4 programs are identical so as they're running out of separate folders stored as follows:

c:\program1\program.exe 
c:\program2\program.exe 
c:\program3\program.exe 
c:\program4\program.exe

Could the PID be retrieved for each program so that the script can distinguish between the 4 and bring the correct one to the front? Any help from the community would be much appreciated.

1
Did you try writing any code?user1944441

1 Answers

0
votes

Here is something, (not tested) to get you started...

SetTitleMatchMode, 1 ; A window's title must start with the specified WinTitle to be a match.
Settimer, CheckWindow, 1000
Return

CheckWindow:
Ifwinexists, ahk_class...... check the class first
{
    IfWinExist, Lab - [Results
        GoSub, MyAlert
    IfWinExist, WARNING
        GoSub, MyAlert
}
Return

MyAlert:
    SoundBeep, 1000, 1000
Return

I see that you have expanded your question with the part discussing 4 similar .exe files. If you want to differentiate based on PID, you can use:

WinGet, active_id, ID, A ; A = active window...
WinMaximize, ahk_id %active_id%
MsgBox, The active window's ID is "%active_id%".

The fact that you ask this question is worrisome. one Google search AutoHotKey PID directs you to the answer. I am willing to help, but not your programmer!

Warning: If you edit your original question, we get no alert UNLESS you also write a new comment!