Posts

AutoKey for Linux

Feb 5, 2022 | 3 minutes to read

One of the things I’ve been missing in Ubuntu is a piece of sofware called AutoHotKey. It’s a Windows-only application that runs in the background and watches for you to type key phrases or key combinations, and then replaces those with whatever you told it to. It’s sort of a macro processor but instead of just working in one app, it works for all applications - a web browser, a terminal window, a text editor, etc… When I used to run my PC on Windows, I used it as a general spelling correcter, and to type out longer things so I didn’t have to do that manually over and over.

For instance, if I accidentally typed, “thigns”, it would replace that text with “things”. If I typed, “PR”, it would replace that with “Peter Ries”. You get the idea. And it was easily extended over time, just by editing a single text file which contained all of my commands.

When I switched to Ubuntu, I quickly realized I missed all that, but since AutoHotKey is Windows-only, I thought I was stuck. But I did some searching today and found AutoKey on github. It’s not as full-featured as the Windows app, but it does what I need.

I am using Ubuntu 20.04 so I just opened my terminal and ran this command to install the latest version:

sudo apt-get install autokey-gtk

Then you can run it like any other application from your desktop. The UI is friendly enough and I quickly picked up how to define the first few “phrases”. It worked right the first time, everywhere I tested it. For simple text replacement, this is going to work very well for me. AutoKey stores its setting in the /home/(user)/.config/autokey/data folder, so I can edit those files directly or use its UI to work on my scripts from now on.

The tool also supports the execution of Python scripts from the same kinds of keyboard triggers. So, for instance, I have a workflow I follow when I am creating a blog post from my PC (like this one), so next I am going to write a script in AutoKey to automate those steps. I could do this with a bach script too, I know, but this looks like a fun, simple tool to explore.

For example, one of the sample scripts the app ships with allows you to insert a date and time string via a Python script. I added an “Abbreviation” for that so that now whenever I type “todaysdate”, the tool replaces that with something like this:

Sat 05 Feb 2022 10:12:28 PM MST

This is what that script looks like in the AutoKey UI:

AutoKey UI

I am digging this and will find new uses for it, I’m sure.


You can leave a comment on this post here.