I'm trying to setup a hotkey to always launch a new WindowsTerminal window and give it focus. Even if there is an existing window, I always want it to create a new window. I'm able to get the new window to run, but I'm having difficulty making it the Active window.
Capturing the pid during the Run
command and using ahk_pid
doesn't seem to work as the pid changes between launch and the active window that appears (msgbox debugging shows one pid, Window Spy shows a different pid). Using WinWait, ahk_exe WindowsTerminal.exe
seems to return right away grabbing a pre-existing window.
#t::
Run, wt.exe, , , TermPid
;; TermPid seems to change between the launch and the final window that appears
WinWait, ahk_pid %TermPid%, , 3
if ErrorLevel {
MsgBox, WinWait timed out... %TermPid%
return
} else {
WinActivate
}
;; problems when there are other already existing WindowsTerminal.exe windows
;WinWait, ahk_exe WindowsTerminal.exe, , 3
;if ErrorLevel {
; MsgBox, WinWait timed out...
; return
;} else {
; WinActivate
;}
return