Managing AutoHotKey Scripts

When I’m working on Windows one of the applications I really miss from the Mac is TextExpander. I’m not the world’s greatest typist and being able to auto correct words I commonly mistype (I can spell by the way - it’s just typing I have issues with) as well as being able to quickly enter common phrases (a.k.a. boiler plate text) is a real boon for me. Fortunately I came upon AutoHotKey - a fantastic free utility that is capable of creating these text based replacements. I’ve been using it for a while now and it occurred to me I haven’t actually shared any of the things I do with it. That’s about to change.

So this is going to be the first of what I hope to be a series of posts on some useful things to do with AutoHotKey, but if you really want to get to grips with it then the application help and forums offer a wealth of information for which I’ll only scratch the surface!

The first thing I thought I’d cover is managing scripts. AutoHotKey is an executable that operates on instructions it is passed via an AutoHotKey script file - *.ahk. Some people load a script based on what they are doing at a particular time (e.g. what PC they’re using, what job they’re doing (e.g. work, playing a particular game, writing their novel). My typical day involves diving in and out of all sorts of applications, getting a bit of personal work (rather than professional work) done during lunch breaks, etc. As a result I don’t actually like having to load different files all the time. Instead I prefer to load just one at boot-up.

By default AutoHotKey will look in the My Documents folder for an AutoHotKey.ahk file. However if you install it or manually associate the .ahk file type, you can load a script into AutoHotKey just by opening it.

As you add more and more instructions to an AHK file I found it could quickly become a bit cumbersome. As a result I’ve split my scripts out into smaller libraries of scripts. I also use Dropbox to keep these files in sync across all of the PCs I use.

In my top level, primary AHK file (that I load directly into AutoHotKey from a shortcut in my start-up menu on each PC) I have two types of include statements. The first is an instruction to “include” the script’s own folder. This in effect sets the working directory for loading further script files (which happen to be located in the same folder). The remaining includes each load another AHK file. Each of these files gives me a kind of categorisation to my scripts. I’ve included a selection of the first few lines of my primary script below:


#Include %A_ScriptDir%

;Load in the controllers
#Include Expansions.ahk
#Include Control.ahk
#Include SAP.ahk

So here I’m loading in “expansions”, which contains is my category for auto-corrects and boiler-plate text; “control” which is all my programmatic stuff (more of those in later posts!); and “SAP”, which has some things in it specifically to do with my work with SAP related systems.

So I actually keep all of my scripts in the same folder, not just my primary and secondary ones. So as you should be able to deduce from that I actually have a tertiary level of scripts. The secondary level of scripts is once again just a file of include statements. Each script being included however is named with the name of the secondary script followed by a hyphen and then a descriptive term. This just makes it easier for me to compartmentalise things when I’m dealing with all of the things I’m getting AutoHotKey to do, but more importantly it lets me easily include or exclude scripts that I’m working on and experimenting with. Isolating them to individual files and include statements makes the whole development process that bit easier (not as many script backups to worry about) and is the key reason I have my set-up like this.

So I’ve included a few of the lines from my Expansions.ahk and Control.ahk files below so you get a better idea.


;EXPANSIONS - auto-correction, common phrases and boiler-plate text

;Load in the expansions
#Include Expansions-Email_Addresses.ahk
#Include Expansions-Names.ahk
#Include Expansions-BoilerPlates.ahk
#Include Expansions-Corrections.ahk
#Include Expansions-Other.ahk


;CONTROL - Scripts for things that control stuff

;Load in the controllers
#Include Control-AltWindowDrag.ahk
#Include Control-AutoHotKey.ahk
#Include Control-FavFolders.ahk

So that’s how I structure AutoHotKey scripts. I guess for the sake of completeness and to bring this post back to how I ended up installing AutoHotKey I should include a selection of some of my auto corrections from my Expansions-Corrections.ahk file. I’m guessing that if you’ve made it this far through the post (and can spell) you’ll get the idea of what the lines are doing.


:*:int he ::in the
Author: Stephen Millard
Tags: | autohotkey |

Buy me a coffeeBuy me a coffee

Related posts that you may also like to read