Good!
I tested my comment. I was wrong, and the script should be OK. If a target window is opened & closed while another is open, in some cases, this may cause the script to proceed, but the window status will still then be detected, and the next loop iteration will begin, which is (usually) OK for most situations.
I would generally suggest adding
#SingleInstance Force so as to avoid multiple instances of this script.
Another variation is below in case helpful. I was testing with Notepad & Chrome here.
Code: Select all
/* Process wait for any in list ---------------------------------
This script waits for any process in a list to exist.
By mikeyww on 01 July 2022 • For AutoHotkey 1.1.34.03
https://www.autohotkey.com/boards/viewtopic.php?p=470649#p470649
-----------------------------------------------------------------
*/
#SingleInstance Force
procList := ["mRemote", "mRemoteNG", "notepad", "chrome"]
waitPerProcessSec := 0.5 / procList.Count() ; Seconds to wait for each process
Process, Priority,, B
Loop {
Loop, 2
For each, proc in procList
Process, WaitClose, %proc%.exe ; Wait for all target processes to end
OnClipboardChange("clipChanged") ; Activate function
SoundBeep, 1500
running := False
While !running ; Wait for one target process to start
For each, proc in procList {
Process, Wait, %proc%.exe, %waitPerProcessSec%
running |= ErrorLevel
}
OnClipboardChange("clipChanged", False) ; Deactivate function
SoundBeep, 1000
}
clipChanged(type) {
OnClipboardChange("clipChanged", False), Clipboard := Trim(Clipboard, " `t`r`n")
OnClipboardChange("clipChanged")
}