Automatically reload AutoHotkey script when modified

Viewed 3114

When testing AutoHotkey scripts, I sometimes forget to reload my scripts after making changes. This leads to me accidentally testing old, outdated versions of my scripts.

Instead of manually reloading the script, I would like to have scripts automatically reload if they have been modified.

How can I make AutoHotkey reload the current script any time a .ahk file is modified?

3 Answers

This is how I've done it:

#If WinActive("AHK.ahk - Notepad") or WinActive("*AHK.ahk - Notepad")
    ~^s::
        Reload
    Return
#If

Checks if the current window is the script that I want autoreloaded whenever I hit Ctrl-S. The ~ means the default action of Ctrl-S (saving the file) is preserved, and then we simply reload it.

I'm still new at AHK but here's what I've come with. If you're using Notepad++ to edit AHKS this will run any ahk that's open and currently in focus in Notepad++ on saving with Ctrl-S and won't effect any other file types.

This script only has to be in one running ahk to work on all ahks being modified in Notepad++.

This can be used on multiple text editor programs too like win Notepad just get rid of the ++ associated with Notepad++

    ~^s:: ; Saves and Runs ANY AHK open in Notepad++
    Sleep 150
    WinGetTitle, Title, A
    Needle := "ahk - Notepad++"
    IfInString, Title, %Needle%
     {  
     StringReplace, xxx, Title,- Notepad++, , All
      run %xxx% 
     return                         
     }      
    else
    return   
Related