Skip to main content

Accessible automation: How AutoHotkey can enhance your daily routine

Learn how AutoHotkey can make your sysadmin work much more time-efficient.
Image
Stairs on an escalator going down.

Escalator by robertgeiger1 is licensed under CC BY 2.0.

When I first became a sysadmin, I was shocked by the speed and precision that my senior colleagues showed when doing basic tasks inside a given terminal or system. These guys would load up bash keys and have a full-stack health check completed inside of five seconds; all the while, I was still trying to enter the initial SSH keys so that I could even start my work. I knew I was competent on the keyboard and quick to pick up new commands that helped simplify my routine tasks, but I was clearly missing something. I finally pushed past my fear of being the FNG (military-speak for "new guy") and asked the question: "What are you all using to speed through these commands?" Whatever it was, it was clearly automated. That was when a good friend introduced me to a simple but effective tool: AutoHotkey.

AutoHotkey is a free open source tool that's used to script a variety of tasks. Anything, from keyboard shortcuts to launch your favorite browser or keystroke and mouse emulation, can be accomplished with this approachable application. With a detailed and well-thought-out how-to, this tool is something that can be used by senior developers and junior admins alike. All that is needed is a text file containing your scripted shortcuts with the correct file extension (all of this is explained in the how-to that comes along with the AutoHotkey download). Allow me to demonstrate the utility that is on offer here.

For basic, everyday phrases that you use with your customers and co-workers, you might type something like this into your hotkey.ahk file:

---
::gm::good morning!
Return

With the script active, this addition would allow you to enter the gm and good morning! would appear, similar to how we communicate over text but in a professional environment. This next example is a personal favorite of mine, as I am a coffee fiend: 

---
::coffee::be right back, going to grab coffee
Return

As before, the portion contained within the double colon is your keyword. The portion after would be displayed on the screen after hitting the Return/Enter key. Both of these examples are great when used in a conversational context, be it Bluejeans or another conferencing tool. 

At this point, you may be thinking to yourself, "That is just lazy." And, if that is all the program could offer, you would be right. However, this is where the app really earns its keep. For technical or work-related tasks, such as loading SSH keys for a particular user in a terminal, you can script something like: 

---
:://adminkey::ssh-agent bash{Enter}ssh-add /home/admin/.ssh/admin_key{Enter}unset TMOUT{Enter}TERM=xterm-color{Enter}
Return

The simple string //adminkey (Enter) would effectively load your bash and user key, followed by unsetting the timeout value for your login and adding color filters to your terminal (which I find very useful). The other thing that I find myself routinely using is the ability to reduce a long file path down to a few simple letters or keystrokes. 

In this example, we will change directories (cd) to /usr/local/*****/var/mc/server_data/prefs/, which contains a configuration file that I often need to reference in my current position. The file path /usr/local/*****/var/mc/server_data/prefs/ can be shortened to mcprefs.

That script would look something like this:

---
::mcprefs::/usr/local/*****/var/mc/server_data/prefs/
Return

AutoHotkey is a great tool that can be powerful when tuned correctly and can act as a sort of "gateway drug" to further interest in automation solutions (see our articles on Ansible). This tool can be used on an individual basis, and at the end of the day, it will increase your overall efficiency with the time that you are given. When we as sysadmins automate even the simplest of tasks, we increase the amount of time that we can now spend on other things—things like professional development, family time, or perfecting that oatmeal porter you’ve been brewing! Either way, it’s a win in my book.

Topics:   Automation  
Author’s photo

Tyler Carrigan

Tyler is a Community Manager at EnableSysAdmin, Submarine Veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a RHEL based combat system inside the USS Georgia Missile Control Center. More about me

Related Content

Image
Linking automation to the bottom line
You'd think it would be easy to convince management that automation saves money. But you might have to prove that the time you spend doing repetitive tasks can be better spent on more strategic work and that the results of automation are good for the bottom line.

OUR BEST CONTENT, DELIVERED TO YOUR INBOX