Search code examples
autohotkey

AutoHotKey Warning: This variable appears to never be assigned a value


#SingleInstance Prompt

global WinGet, WindowList, List

; Get a list of all open windows
WinGet WindowList, List

; Loop through the list and display information about each window
Loop % WindowList %
{
     ; Get the window title and process name
     this_id := WindowList%A_Index%
     WinGetTitle Title, % "ahk_id " % this_id
     WinGet ProcessName, ProcessName, % "ahk_id " % this_id

     ; Display information
     MsgBox Window %A_Index% `nTitle  %Title%`nProcess %ProcessName%
}

gives

enter image description here

What am I doing wrongly?


Solution

  • AutoHotkey v1:

    #Requires AutoHotkey v1.1
    
    #SingleInstance Prompt
    
    ; Get a list of all open windows
    WinGet, id, list,,, Program Manager
    
    ; Loop through the list and display information about each window
    Loop, %id%
    {
         ; Get the window title and process name
         this_ID := id%A_Index%
         WinGetTitle Title, ahk_id %this_ID%
         WinGet ProcessName, ProcessName, ahk_id %this_ID%
         
         ; Display information
         MsgBox Window %A_Index% `nTitle:  %Title%`nProcess:  %ProcessName%
    }
    

    https://www.autohotkey.com/docs/v1/lib/WinGet.htm

    AutoHotkey v2:

    #Requires AutoHotkey v2.0
    
    #SingleInstance Prompt
    
    ; Get a list of all open windows
    ids := WinGetList(,, "Program Manager")
    for this_id in ids
    {
       ; Get the window title and process name
       title := WinGetTitle(this_id)
       ProcessName := WinGetProcessName(this_id)
        
       ; Display information
       MsgBox("Window " A_Index "`nTitle: "  title "`nProcessName: "  ProcessName)
    }
    

    https://www.autohotkey.com/docs/v2/lib/WinGetList.htm