I'm trying to figure out the best way to create a simple text expander using Python. Do you have any suggestions for me?
I'm running Linux (Lubuntu 20.04 LTS). I am only looking for a solution that works on Linux. By the way, as an aside, I presume my solution would work on Macintosh OS as well. As for Windows, I'm not sure.
I've been using AutoKey on Linux (which is different than, and distinct, from the similarly named AutoHotKey which runs on Windows) for about 6 or 7 years. It works pretty well but it crashes sometimes and is no longer being actively developed.
Essentially I use AutoKey as a text expander. For example, if I type .tflmk
then AutoKey will replace .tflmk
with Thanks for letting me know.
I wanted a simpler, more reliable solution that AutoKey that would not require me to install an application that might become essentially orphaned.
After some research I found that by adding the following lines...
alias paste-script-1="nohup python3 '~/home/script-1.py' --option& exit"
alias paste-script-2="nohup python3 '~/home/script-2.py' --option& exit"
alias paste-script-3="nohup python3 '~/home/script-3.py' --option& exit"
to
.bashrc
I could run Python scripts from a terminal that would paste into, say, a text document I was working on or a Gmail I was composing, if the Python scripts contained the following information...
import pyautogui,pyperclip
x = '''I will get back to you later today.'''
pyperclip.copy(x)
pyperclip.paste()
pyautogui.hotkey('ctrl', 'v') # ctrl-v pastes.
which I could trigger by typing .iwgbtylt
into a terminal if the following line were in my .bashrc
file...
alias .iwgbtylt ="nohup python3 '~/home/IWillGetBack....py' --option& exit"
and, of course, if I had created the file /home/IWillGetBack....py
.
I posted this question How can I send a string from script_1 to script_2? because it seemed better to me to segregate the each of my text expanders from a "main script" in case I wanted to make changes to the main script.
I expect I will end up with several hundred "text expander snippets" that are located in half a dozen or so sub-directories under a folder such as ~/home/my_text_expanders
.