Replaces the currently running instance of the script with a new one.
This command is useful for scripts that are frequently changed. By assigning a hotkey to this command, you can easily restart the script after saving your changes in an editor.
By default, the script can also be reloaded via its tray icon or main window.
[v1.1.34+]: If the /include switch was passed to the script's current instance, it is automatically passed to the new instance.
Any other command-line parameters passed to the script's current instance are not passed to the new instance. To pass such parameters, do not use Reload. Instead, use Run in conjunction with A_AhkPath and A_ScriptFullPath (and A_IsCompiled if the script is ever used in compiled form). Also, include the string
/restart as the first parameter (i.e. after the name of the executable), which tells the program to use the same behavior as Reload. See also: command line switches and syntax.
When the script restarts, it is launched in its original working directory (the one that was in effect when it was first launched). In other words, SetWorkingDir will not change the working directory that will be used for the new instance.
If the script cannot be reloaded -- perhaps because it has a syntax error -- the original instance of the script will continue running. Therefore, the reload command should be followed by whatever actions you want taken in the event of a failure (such as a return to exit the current subroutine). To have the original instance detect the failure, follow this example:
Reload Sleep 1000 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached. MsgBox, 4,, The script could not be reloaded. Would you like to open it for editing? IfMsgBox, Yes, Edit return
AutoHotkey relies on the title of the script's main window to identify other running instances of the script.