Automate Your Workflow With AutoHotkey

Have you ever wanted to automate tasks that you perform often, or map keyboard shortcuts to make your life easier? Well, I have the answer and it’s AutoHotkey.

AutoHotkey is a free, open-source application that allows you to create and run scripts to automate your workflow. Let’s see how easy it is to program with AutoHotkey and automate your workflow.

Getting Started

Download the installer (regular version or portable) and walk through the installation wizard. Once you have launched AutoHotkey for the first time, you’ll be asked if you want to launch a sample script.

If you haven’t used AutoHotkey before, it’s a good idea to start with the basics.

Sample Script for AutoHotkey

Sample Script for AutoHotkey

The Basics

An AutoHotkey script is a text file with executable commands. The script will contain hotkeys and hotstrings, and sometimes other commands. 

A hotkey is also known as a shortcut because it triggers a command (for example, Win+N launches Notepad). A hotstring is a hotkey that is more than one charcter (like expanding fyi to for your information).

Create a Basic Script

One of the most common uses for AutoHotkey is to launch applications, documents, or websites.

For example, let’s create a hotkey to launch Notepad by pressing the Windows button plus the letter N. Open your favorite text editor and create a new file. Add the following line to your file #n::Run Notepad and save it with the extension .ahk. Then run your script by double-clicking it, and your new hotkey should launch Notepad. This is what your script file looks like.

Notepad.ahk Script to Run Notepad by Shortcut Win+N

Notepad.ahk Script to Run Notepad by Shortcut Win+N

This example is a single-line hotkey because it is only one command: launch Notepad when I press Win+N.

Multiple Line Scripts

If you want to execute more than one command, you set it up a little differently. Put the first line beneath the definition and the line last should be a return.

An example would be if you want to launch Google in your default web browser and launch Notepad, all with one hotkey.

#n::
Run http://www.google.com
Run Notepad.exe
return

Launch Google and Run Notepad with Win+N

Launch Google and Run Notepad with Win+N

If you want to launch a program that isn’t built into the system, like Notepad++ instead of Notepad, specify its full path. This is how you would launch Notepad++ when you hit the shortcut Win+N.

Script to Run Notepad++ on Win+N

Script to Run Notepad++ on Win+N

Sending Keystrokes

AutoHotkey gives you the ability to send keystrokes to applications. Let’s say you have to type a company greeting regularly and you want to make a script for it. When you type Control+Alt+G in a text area, your greeting will appear.

Script for Control+Alt+G to Send a Phrase

Script for Control+Alt+G to Send a Phrase

With the above script, AHK will send “Thank you for contacting AppStorm. My name is Sydney. What can I help you with today?” to the active window, such as an email, Word document, or form field.

If you change windows while AutoHotkey is sending the keystrokes, they will move to the new active window. Also, make sure you are in the text area you want before typing the shortcut.

Sending Mouse Clicks

In order to send mouse clicks with AutoHotkey, you need to use Windows Spy or AutoScriptWriter to find the exact coordinates. Let’s start with a script to play Pandora when it is paused.

Launch Windows Spy and make Pandora your active window (Windows Spy will stay on top). When the cursor is hovering on the play button, Windows Spy says the mouse position is 144, 347 in the active window, so these are the numbers I will use for my script.

 

Getting Coordinates for Pandora Play Button in Windows Spy

Getting Coordinates for Pandora Play Button in Windows Spy

The script I am using says to look for an active window titled Pandora, and if that window is found, click the coordinates given.

IfWinExist, Pandora
{
   WinActivate 
   Click 144, 347
}

We can add additional commands to this script, such as launching Pandora if it’s not already open, and doing all of this when you press a hotkey. So, let’s say you want to play music on Pandora when you press Control+Alt+M. If Pandora is already open, it will send a mouse click to play. If Pandora is not open, it will launch the application.

Script to Launch or Play Pandora on Control+Alt+M

Script to Launch or Play Pandora on Control+Alt+M

Other Possibilities

You can have multiple commands in one script file. For instance, I have a script I always run that has commands for different hotkeys to launch applications, and also to map certain keyboard shortcuts like plain text pasting. This way you only have to run one script all the time to access these commands.

Another cool feature to help automate your workflow is to manipulate files and folders. You can add and remove text, overwrite files, and do so many things. AutoHotkey also lets you repeat a series of actions many times by using a loop.

You can also use variables, perform math operations and manipulate your clipboard data. A very useful script is to paste your clipboard in plain text when typing a hotkey. To paste plain text when typing Control+Alt+V, use the following script.

Paste Clipboard Contents in Plain Text on Control+Alt+V

Paste Clipboard Contents in Plain Text on Control+Alt+V

AutoHotkey gives you the option to convert scripts into .exe files so they can be run on a computer that doesn’t have AutoHotkey installed, allowing you to create your own apps.

You can also remap keys and shortcuts to customize your keyboard for more efficiency during your everyday routine. AutoHotkey allows you to manipulate your machine in almost any way you want, opening your workflow up to unlimited possibilities.

Learning Curve

Programming with AutoHotkey is fairly easy, especially if you have some programming experience. The language is very simple to learn and understand, and running and using existing scripts can be done by anyone.

AutoHotkey’s documentation is incredible – you can easily read through and understand how to create your own scripts.

Community & Development

According to the website and Github, AutoHotkey hasn’t released a new version or changes since 2009. However, the forums are actively maintained so you can get help from other users easily and quickly. You can also find scripts that others have written to enhance your productivity.

AutoHotkey is a wonderful tool that gives you the opportunities to automate tasks so you can improve your workflow. For more documentation and scripts, visit AutoHotkey.com.


Summary

AutoHotkey is a free, open-source utility for Windows. With it, you can automate almost anything by sending keystrokes and mouse clicks. You can write a mouse or keyboard macro by hand or use the macro recorder.

8