Reloading AutoHotKey Scripts

So this post is just a quick tip for anyone getting started with AutoHotKey. Whilst editing an AHK script, you probably often find you need to reload the script into AutoHotKey. Whilst this is available from the application icon in the notification area, it seems ludicrous to have to do for an application called AutoHotKey - why not trigger a reload with a key press? Well the answer’s in the help file…

If you look up “Reload” in the AutoHotKey help file, it explains all about the Reload command which reloads the current script. They even provide a little example script that they attach to CTRL+ALT+R. I’m not going to claim any great insight here, but if you are starting out then I’d really recommend adding this to any AutoHotKey script you have - at least during development.

My own version has one small amendment which is to put up a quick visual notification that it is reloading the script. I added this after I had a moment trying to work out why the reloaded script wasn’t working - it turned out AutoHotKey had crashed, but I had no clue that I wasn’t actually running the reload. Now I get a visual cue to tell me, but you could just as easily add an audio cue.

So this is the example script from the AutoHotKey help file with my extra ‘notification’ lines:

;Reload the current AutoHotKey script
SplashTextOn, , , Reloading....
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

There are also options for making the reload process automated. For example periodically checking if you script file(s) has(/have) been updated by checking timestamps or archiving attributes. you could even watch for saving any *.AHK files from your favourite text editor. For me I like to choose when to reload as I might be modifying several script files before wanting to refresh … but with AutoHotKey your options are vast.

Author: Stephen Millard
Tags: | autohotkey |

Buy me a coffeeBuy me a coffee

Related posts that you may also like to read