Whenever I face a repetitive task, I wonder if there’s a way to automate it to make it go faster. This weekend, for instance, I had to spot over 600 subtitles (i.e., set the times when a subtitle will appear and disappear from the screen). This involved the following steps:
- Select a portion of audio from a waveform in Subtitle Edit.
- Switch over to the file containing the script in Notepad++.
- Select the subtitle text.
- Copy the selection to the clipboard.
- Switch back to Subtitle Edit.
- Click the right mouse button.
- Select the second option from the context menu to create a new subtitle and then paste the contents of the clipboard in it.
These steps needed to be repeated for each subtitle—so, 600 times. Clearly, this was a perfect opportunity to automate a repetitive task. I could have sped up the process had I combined at least some of those steps into a customized macro (i.e., a saved sequence of commands that instructs the computer to perform a given task). With a single click or keyboard shortcut, I could have activated the macro and saved repetitive clicks and key presses.
This is only one example of the many times during my work as a translator when I’ve found myself wishing I had a macro to save time. Since discovering AutoHotkey, however, I’ve gone from wishing there was a way to speed things up to actually making it happen.
What Is AutoHotkey?
AutoHotkey is a free open-source scripting language for Windows that allows users to create macros to automate all kinds of repetitive computer tasks in any Windows application. AutoHotkey scripts can be used to launch programs, open documents, and emulate keystrokes, Unicode characters, and mouse clicks and movements.
The best part is you don’t need to be a programming whiz to take advantage of AutoHotkey and start using it right away. While it’s powerful enough to allow advanced users to create complex automation processes, it also allows non-programmers like myself to quickly learn the basics and start creating simple scripts to suit our needs.
What do you need to get started? First, go to www.autohotkey.com and download the program. (The AutoHotkey installation includes its own extensive help file, and web-based documentation is also available.) Once downloaded, install the program. Keep in mind that installing AutoHotkey doesn’t launch the program automatically or do anything else, so don’t worry if it looks like nothing happened.
With AutoHotkey installed, you’re now ready to start creating your own sequences of actions to be launched with one of two AutoHotkey features: hotstrings and hotkeys.
A hotstring is a string (or sequence) of text typically composed of more than one character (usually forming an abbreviation) that can be used to trigger any scripted action. Hotstrings are commonly used for text expansion. For example, I can assign the character string “ak” to automatically produce the word AutoHotkey:
What you’re looking at is a text expansion triggered by a hotstring. It means that when I press the keys “ak” (the hotstring), followed by an ending character (e.g., a space, punctuation mark, or the Enter key), the word AutoHotkey will automatically appear on my screen. The syntax for a hotstring is a pair of colons, the abbreviation you want to use to trigger the expansion, and another pair of colons. After the second pair of colons, you enter the expanded text you want to see when you type the abbreviation. Here’s another example:
::addr::1600 Pennsylvania Avenue NW, Washington, DC 20500, United States
In this example, typing the hotstring “addr” followed by an ending character (a space, a punctuation mark, or the Enter key) will cause the address of the White House to be typed out.
Creating a Hotstring Script
Now, where do you put these hotstrings so you can use them? You put them in an AutoHotkey script. Follow the steps below to create your very first script. (Tip: If you’re like me, you’ll soon have a large number of scripts, so it makes sense to create a folder just for AutoHotkey scripts.)
- In your selected folder, right-click and select New—AutoHotkey Script. Name your script anything you want. (Note that the extension of the new file is “.ahk”.) Now you need to add the hotstrings to the script. This is done in a plain text editor. I suggest using Notepad++, which is also free, so if you don’t have it, head over to notepad-plus-plus.org to download and install it.
- In the folder where you saved the script, right-click on the file and select Edit with Notepad++. The file that opens contains four lines of text, which is the “skeleton” of an AutoHotkey script. (See Figure 1.) The text that appears after the semicolon on each line explains what the line does. In Figure 1, you’ll see I’ve placed my cursor in line 5, which causes it to be highlighted. Although line 5 is the first line where we can start entering our hotstrings, I usually leave it blank to create space between the first four default lines and my own.
- Place your cursor in line 6 and enter the sample hotstrings from the previous examples I gave (::ak::AutoHotkey and ::addr::1600 Pennsylvania Avenue NW, Washington, DC 20500, United States), each on its own line. (Remember the hotstring syntax: a pair of colons, followed by the abbreviation, another pair of colons, and the text to be expanded.) Now your script will have seven lines, two of which are hotstrings. (See Figure 2.)Of course, you can add more hotstrings to your script. In Figure 3 you’ll see I’ve added a third hotstring for my email address in line 8.
- Save your file. Now before you can use your hotstrings, you’ll need to activate the script.
- To activate a script, go back to the folder where your script is saved and double-click it. This will “load” the script, which means it will be enabled from now on, unless you unload it or restart your computer. You’ll know that the script is loaded because a green square icon with a white “H” in it will appear in the system tray.Now you’re ready to start using your hotstrings. Go to any program where you can enter text (e.g., Notepad++, Word, a web browser, your computer-assisted translation (CAT) tool) and type one of your hotstrings followed by a space, a punctuation character, or the Enter key, and see the expanded text you created appear automatically on your screen.When you’re ready to add more hotstrings to your script, open the file again in Notepad++, add new lines, and save it. After doing this, you’ll need to reload the script for the new changes to take effect. To do this, go to your system tray on the bottom right corner of your screen, find the green icon with the white “H” in it, right-click it, and select Reload This Script.
Now that you understand the basics of creating a script and loading it, it’s time to try something a bit more advanced: hotkeys.
Hotkeys are sometimes referred to as shortcut keys because of their ability to easily trigger an action
(such as launching a program or keyboard macro). Before we look at an example, consider the following AutoHotkey basics:
- ! is the Alt key.
- ^ is the Control key.
- + is the Shift key.
- The hotkey (key combination) needs to be followed by a pair of colons.
- The word Return is always the last line in a hotkey script, and it indicates the end (i.e., where the script will stop).
- The word Send is a command indicating that keys will be pressed.
- Key names need to be enclosed in curly brackets.
- The word Sleep is a command indicating wait time. It’s usually used to give the computer time to complete a command before moving to the next one.
With this information, you’ll be able to understand the script below.
Don’t worry if this still isn’t clear. Let’s break it down.
Understanding the Script
This is the hotkey (or shortcut) that will be used to trigger the sequence of actions. You can select the hotkeys you want to use. For this example, I chose Alt+X, but you can choose anything you want. Notice the pair of colons that designates this as the hotkey. This is important because, as I mentioned earlier, the hotkey (key combination) needs to be followed by a pair of colons.
This action means that the Control and Left arrow keys will be pressed (not physically, but rather programmatically). In Word or in a CAT tool, for example, this will send the cursor to the beginning of the current word if the cursor is in the middle of a word, or to the beginning of the previous word if the cursor is already at the beginning of a word.
This line tells the computer to wait 200 milliseconds before executing the next line. This is recommended to provide enough time for an action to be completed before the next action is started. In fact, if you ever need to troubleshoot a script, it’s a good idea to add wait times longer than one second between lines so you can see the actions play out slowly.
This line will press Shift and the Right arrow key, which will cause one character to be selected to the right of the cursor.
This tells the computer to wait another 200 milliseconds before executing the next line.
This line will press Shift and F3, which will cause the selected character to change case.
Wait another 200 milliseconds.
This command presses the Right arrow key to move the cursor one character to the right and deselect the previous character.
This signifies the end of the script. When all the actions between the hotkey and the Return line have been executed, the script will stop, and any lines in the script file below the Return line will not be executed as part of this hotkey.
I use this script to quickly change the case of the first letter of any word my cursor is resting on. Whenever I’m editing a translation and see that a word needs to have an initial case change, instead of manually going to the beginning of the word, deleting the lowercase letter, and typing in the uppercase one, or vice versa, all I need to do is press Alt+X. Sometimes I’ll keep my right hand on the mouse to click anywhere on the appropriate word and use my left hand to press Alt+X to quickly make the edit. As simple as this sounds, it’s a huge time saver.
Creating a Hotkey Script
To create a hotkey script, follow the same steps you used to create a hotstring script:
- Right-click in your folder.
- Select New—AutoHotkey Script.
- Name your script file.
- Right-click on the script file and select Edit with Notepad++.
- Enter your script in Notepad++.
- Save the file.
- Load it by double-clicking the name of the script. (See Figure 4.)
Once you’ve done this, go to Word or your CAT tool, place your cursor in the middle of any word, press Alt+X, and watch the initial letter of that word change case.
Another way you could do this instead of creating a new script file is to add the new lines to the existing hotstring script and save and reload it. In other words, you can combine several hotkeys and hotstrings into a single script file, or you can create separate script files.
There’s a lot more to learn about AutoHotkey, such as triggering hotstrings without an ending character, making scripts program-sensitive, and sending mouse clicks, but I hope this brief introduction will pique your curiosity and inspire you to learn more. For complete information on all the concepts discussed here, please check out the extensive reference section on the AutoHotkey website: www.autohotkey.com/docs/AutoHotkey.htm.
Nora Díaz has a BA in English-language teaching and translation. She is a full-time English>Spanish translator and translation team leader. She works for clients around the world translating, editing, and proofreading content on a wide variety of topics, including health care, legal, technical, and general texts. She leads linguistic teams, including translators, editors, and proofreaders, from Mexico, South America, and Spain working on large projects. Her interest in productivity has led to a constant exploration of technology to boost productivity, such as computer-assisted translation tools, speech recognition, and custom macros. In her blog, Nora Díaz on Translation, Teaching and Other Stuff, she shares what she has learned with translators from around the globe. firstname.lastname@example.org.