Reload

Replaces the currently running instance of the script with a new one.

Reload

This function is useful for scripts that are frequently changed. By assigning a hotkey to this function, 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.

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, use Run with A_AhkPath and A_ScriptFullPath (and A_IsCompiled for a compiled script).

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 function 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.
Result := MsgBox("The script could not be reloaded. Would you like to open it for editing?",, 4)
if Result = "Yes"
    Edit
return

After compiling, the replacement asks the instance that launched it to exit. An OnExit callback may prevent that exit; the replacement then asks whether to keep waiting. Without a desktop UI, the replacement exits if the previous instance does not close. On Windows, headless scripts exit before relaunching because they have no window message loop.

Edit

Examples

Press a hotkey to restart the script.

^!r::Reload  ; Ctrl+Alt+R