There was a utility I used quite a lot in my macOS days called Typinator. Simply put, it watched what you typed and replaced certain text strings with other (usually much longer or more complicated) ones. It was handy for things like typing my address, the date, my phone number, or medical provider ID — things I had to do dozens of times a day thanks to the endless paperwork burdens imposed on doctors by insurance companies and regulators.
When I switched to Linux as my daily driver, I was surprised that no equivalent utilities existed for Linux distributions using Wayland. It was actually the only software I used on macOS for which I was unable to find an equal-or-better replacement in Linux.
I did run across Espanso and tried to use it for over a year. The problem is that it would periodically (more than once a day) stop triggering on text strings — rendering it pretty much useless. I filed a bug report with the developers, and learned that others were having the same problem, not just on Linux but on Windows and macOS machines as well. I doggedly persisted, but the program was sooooo frustrating to use and the developers showed little interest in fixing it.
I decided to take matters into my own hands. KDE Plasma (the desktop environment I use) comes with a program called KRunner that can be invoked with a single keystroke, then do all manner of operations selected with a few more keystrokes. KRunner is indispensable to me, and I thought I could add my essential abbreviations to KRunner and have it expand them as I type. Since KRunner can run command-line utilities, my plan was to create a bash script for each of my shortcuts, then run them with KRunner. For example, with Espanso I had the shortcut xdd
expand to the current date in YYYY-MM-DD format, which is what the twoprops.net
web software uses.
First, I had to figure out how to get keystrokes to the frontmost window of my desktop environment. On X Window systems, the popular choice is xdotool
, but it doesn’t seem to work under Wayland. The right program is the newer ydotool
.
install ydotool
sudo dnf install ydotool
I’m running Fedora; presumably apt install ydotool
would work on debian-based distros.
get the daemon running
$ export YDOTOOL_SOCKET="$HOME/.ydotool.socket" # this probably belongs in your .bashrc or equivalent shell initiation file
$ sudo systemctl enable ydotool
create the abbreviation files
I chose to create a separate file for each expansion, in a directory in my $PATH. For example, the file dd
(on my system, /home/twoprops/.local/bin/dd
) implements the dashed-date expansion.
#!/bin/bash
ydotool type "$(date +%Y-%m-%d)"
To invoke the expansion, I press alt-space, dd, return. (On most installs, alt-space will invoke ‘KRunner’.) Not quite as convenient as typing “xdd” with Espanso running — if Espanso is actually working at the time.
Some sample expansions I use:
abbreviation | expansion |
---|---|
bar | ydotool type '\--=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-' |
dater | ydotool type "$(date +%d-%b-%Y)" |
ds | ydotool type "$(date +%Y%m%d)" |
iso | ydotool type "$(date +%Y-%m-%dT%H:%M%:z)" |
The text you send to ydotool can include newlines \n
, tabs \t
and expanded command-line commands (as with $(date)
, above, or substituting the clipboard with $(wl-paste)
). You can send special keystrokes and even move the mouse with ydotool as well, see ydotool help
for details.
—2p