Search code examples
autohotkey

How can I use "name" from wmctrl?


When I do "wmctrl -l" from WSL2, I get

wmctrl.exe -l
ID:      Name:   Title:
-------------------------------------------------
13028    WindowsTerminal         C:\WINDOWS\system32\wmctrl.exe

..and when I do it from Windows, I get this:

ID:      Name:   Title:
-------------------------------------------------
13028    WindowsTerminal         Windows PowerShell

How can I use this in AutoHotKey, cause I seem only to be able to use the Title, as this will not work:

^!+t::
if WinExist("WindowsTerminal")
   WinActivate 
else
   Run wt
return

I'm able to match "Power", but that is the "title", which I don't want to match. I want to match on "name".

Also, what is the "name" here? It's not the executable name and it's not the Window Manager title, so I'm not sure what it really is;)


Solution

  • Use the Window Spy tool to retrieve information about that window:

    Selecting window spy Window Spy in use

    If the window's title isn't always the same, you can use its ahk_class or/and ahk_exe:

    ; e.g. for explorer:
    if WinExist("ahk_class CabinetWClass")
       WinActivate
    
    ; or:
    if WinExist("ahk_exe explorer.exe")
       WinActivate  
    
    ; or:
    if WinExist("ahk_class CabinetWClass ahk_exe explorer.exe")
       WinActivate