Auto-reboot AutoHotkey script when changing

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

Instead of manually reloading the script, I would like the scripts to automatically reload if they were changed.

How can I get AutoHotkey to reload the current script anytime the .ahk file is modified?

+2
source share
1 answer

Somewhere near the start of the script in the auto-execute section

 #SingleInstance force FileGetTime ScriptStartModTime, %A_ScriptFullPath% SetTimer CheckScriptUpdate, 100, 0x7FFFFFFF ; 100 ms, highest priority 

Anywhere in the script (usually somewhere below):

 CheckScriptUpdate() { global ScriptStartModTime FileGetTime curModTime, %A_ScriptFullPath% If (curModTime <> ScriptStartModTime) { Loop { reload Sleep 300 ; ms MsgBox 0x2, %A_ScriptName%, Reload failed. ; 0x2 = Abort/Retry/Ignore IfMsgBox Abort ExitApp IfMsgBox Ignore break } ; loops reload on "Retry" } } 
+2
source

All Articles