Automation – AutoHotKey
AutoHotKey is a macro and scripting tool for windows that lets you automate all kinds of repetitive tasks. This tool is free (which should fit in most budgets) to download and use. The software can be downloaded from their website.
Installation is pretty simple by stepping through the wizard. Once done the application will be installed on your computer ready for you to command it to do the tedious or repetitive things on your behalf.
After the installation of AutoHotKey, it will create a new file association with text files with an .ahk extension. These files are scripts or tasks we create and are interpreted by the AutoHotKey software.
Let’s create a simple script for our new software to begin helping us.
Open notepad on your computer and enter the following:
::lmka::
send Let me know if you need anything. {Enter}{Enter}
send Thanks, {Enter}{Enter}
send Larry {Enter}
return
If you are using notepad and try to save the script, the file will have a .txt extension. When saving the file, select the “all files” from the save as type dropdown and name the file “common.ahk”. The .ahk is important do not forget the add it. I would recommend creating a folder in your “my documents” folder, naming it “AHK Scripts”, and saving it this location. Having a central location makes things easier to find in the future as you enhance your scripts. Trust me, you will be visiting these scripts often and you begin to embrace the world of automation.
Close notepad and locate the file where you saved it. If all went well, your file will have a small icon () next to it with a while H on it. This is an AutoHotKey script file. Right click on the file and select “Run Script” from the list of options. Your script is now running and monitoring what you do (in a good way).
Open notepad again and type “lmka” (without the quotes) and watch AutoHotKey go to work. It should have typed the following for you:
“Let me know if you need anything.
Thanks,
Larry”
You might have changed the name in the script (unless your name is Larry). If not, we can edit the file and change anything we like our script to write.
Lets’ look at the script again:
::lmka::
send Let me know if you need anything. {Enter}{Enter}
send Thanks, {Enter}{Enter}
send Larry {Enter}
return
The ::lmka:: defines the letter sequence AutoHotKey is watching for to generate the replacement text.
TIP: try to use at least 3 characters and not something normally put together i.e. “ing” or “and”. AutoHotKey is smart enough to not inject the text when the pattern is found in a word. However, it will trigger the text replacement if the next character after your text is a punctuation or carriage return.
The “send” command tells AutoHotKey to type the following until a carriage return or end of line marker. Note that we do not use quotes or any special identifier for our simple text.
The {Enter} tells AutoHotKey to send the enter command to insert a new line
Finally, the return command informs AutoHotKey that the end of the script snippet has been reached.
Multiple Scripts Snippets in a File.
A file can contain multiple snippets of code allows a file to accomplish a multitude of tasks. Let’s extend the common.ahk file.
Open file explorer and locate the common.ahk file.
Right click on the file and select edit
You should now see your previous script
Copy the script and then past the text below the current text so it looks like this:
::lmka::
send Let me know if you need anything. {Enter}{Enter}
send Thanks, {Enter}{Enter}
send Larry {Enter}
return
::lmka::
send Let me know if you need anything. {Enter}{Enter}
send Thanks, {Enter}{Enter}
send Larry {Enter}
return
Change the second ::”lmka”:: to ::”lmkp”::
Change the second line in the new script block to send Let me know if you need problems. {Enter}{Enter}
The scripts should now look like this:
::lmka::
send Let me know if you need anything. {Enter}{Enter}
send Thanks, {Enter}{Enter}
send Larry {Enter}
return
::lmkp::
send Let me know if you need problems. {Enter}{Enter}
send Thanks, {Enter}{Enter}
send Larry {Enter}
return
Save your work and close the window.
Right click on the file and select run script (if the script is already running you will get a popup message asking if you want to replace the running instance. Click Yes.
Now your script can perform two tasks!
Lmka gets:
“Let me know if you need anything else.
Thanks,
Larry”
Lmkp gets:
“Let me know if you have any problems.
Thanks,
Larry “
Let your mind wonder and begin to think of other little (or long) text snippets you type on a regular basis. Anytime you type a phrase you think you might need to type again, edit your script and let AutoHotKey type it for you in the future. We will continue our series with some other features of AutoHotKey to help make your repetitive tasks a little less tedious.