I have a lot of repetitive tasks I do throughout the day. For example, I have to type out the same long header for articles regularly. At one point, I saved a file that contained the header contents but realized using it caused me extra clicks, all of which amounted to making my day a bit less efficient. There are also the Netplan configurations I make daily. I frequently deploy Ubuntu Server as a virtual machine, and having to always configure networking is just one more step I don’t want to have to take.

How to become a network administrator: A cheat sheet (TechRepublic)

That’s why I employ a little Linux tool called AutoKey, which is a GUI application for creating boilerplate text files and more complicated macros that can be used for just about anything. Once you’ve created a new “phrase” you can assign the phrase a hotkey. With the phrase complete, all you have to do is hit the hotkey and the phrase is then added to the document you are using.

AutoKey also allows you to create “scripts,” which are more advanced options that allow you to do things like open applications/files/folders, control window and mouse events, display menu entries to select from, and other things.

I’m going to show you how to install AutoKey on a Debian-based distribution and then walk you through how to create a phrase that will paste the contents of Netplan into an open file.

What you’ll need

To make this work, you’ll need a running instance of a Debian-based Linux desktop (I’m using Pop!_OS 21.04) and a user with sudo privileges. That’s it. Let’s make some desktop magic.

How to install AutoKey

AutoKey can be found in the standard repositories. There are two editions: A GTK and Qt variant. Which you install will depend on the desktop environment you are using. For instance, if your desktop of choice is GNOME, you’ll install the GTK version of AutoKey. If, on the other hand, you use KDE, the Qt version is what you want.

To install the GTK version of AutoKey, open a terminal window and issue the command:

sudo apt-get install autokey-gtk -y

To install the Qt version, the command is:

sudo apt-get install autokey-qt -y

Once the installation is complete, you’ll find an AutoKey entry in your desktop menu. Launch the application and then set it to run at boot by clicking Edit | Preferences and then click the checkbox for Automatically start AutoKey at login (Figure A).

Figure A

Configuring AutoKey to run at start.

How to create your first phrase

We’re now going to create our first phrase that will paste the contents for a Netplan network configuration (so you don’t have to always remember the layout or type it out manually). From the AutoKey window, click the New drop-down and select Phrase. In the popup, give the phrase a name (such as NETPLAN) and click OK.

With the new phrase created, you’ll then add the contents of your Netplan file in the upper right pane (Figure B).

Figure B

Adding the contents for a Netplan configuration into AutoKey.

With the Netplan contents in place, it’s time to assign a hotkey. In the Phrase Settings pane, click the Set button associated with Hotkey. A new window will pop up (Figure C). Click Press to Set.

Figure C

Setting a hotkey combination for our new phrase.

You will then type the key combination you want to use for the phrase. Once you’ve done that, press OK to close the popup. Finally, click Save and your phrase is ready to go.

How to use a new phrase

At this point, open a connection to a newly deployed Netplan-enabled server, open the netplan configuration (or create a new one), and then hit the newly created hotkey to have the contents of the phrase pasted into the file. You’ll probably need to alter the IP address for the configuration, but you won’t have to either remember the YAML configuration for netplan or type out the entire configuration manually.

At this point, you’re probably asking yourself, “How did he SSH into that virtual machine if networking hasn’t been already configured?” The way I work this is to create a fairly standard virtual machine, with a basic working network configuration. I then clone the basic machine (knowing the default IP address I’ve set in the basic configuration), SSH into that machine, and alter the Netplan configuration as needed.

This is just one of the many ways you can use AutoKey. I’ve found this tool to be invaluable for helping make my day a bit more efficient. Give AutoKey a try and see what clever use cases you can come up with for the tool.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Image: jivacore/Shutterstock