Hotkey to restart autohotkey script?

Say my autohotkey script is running C:\path\to\my\script . Is there a way to identify a hotkey that restarts it?

+5
source share
3 answers

To avoid duplicate instances, I usually do not restart the script, but use the built-in Reload function. I run this with Ctrl + Win + Alt + R and use Ctrl + Win + Alt + E to edit the main AHK script.

 ^#!r::Reload 

Actually, my script looks like this:

 ^#!r:: Send, ^s ; To save a changed script Sleep, 300 ; give it time to save the script Reload Return ^!#e::Edit 

In fact, all this is at the top of my script, I got this to give me a visual and audible indication of the restart of the script:

 #SingleInstance Force #installKeybdHook #Persistent Menu, Tray, Icon , Shell32.dll, 25, 1 TrayTip, AutoHotKey, Started, 1 SoundBeep, 300, 150 Return 
+8
source

Make a hotkey that runs the script, which in this case is the same script, and then exits.

 somehotkey:: Run, C:\path\to\my\script.ahk ExitApp return 
+1
source

I found that this is the safest option of all, because it takes care that the correct script is reloaded when you have several scripts running at the same time, which was a constant problem for me. The combination of the following also ensures that only one instance of the script will work at a time. The variable ScriptFullPath includes the name of the script.

 #SingleInstance Force ;put this at the top of the script ^r::run, %A_ScriptFullPath% 
0
source

All Articles