0

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.

Tiel
  • 87
  • 1
  • 9

2 Answers2

0

I am using a super simple text expander for my personal use, which I implemented with a Python module 'keyboard' (https://github.com/boppreh/keyboard). I'm working on Windows, but it seems that it can also be used for Linux (and Mac). At its simplest form, I just run the following code during my work (writing CT reports).

import keyboard

abbrev_dict = {
  "ac": "ascending colon", "bl": "benign-looking",
     ...(omitted)... 
  "_vc": "Multifocal atherosclertoic vascular calcification in aorta and its branches."}

for (source, target) in abbrev_dict.items():
    keyboard.add_abbreviation(source, target)

keyboard.wait()
buddemat
  • 4,552
  • 14
  • 29
  • 49
0

Just FYI:

Seems that AutoKey has not been totally no longer being actively developed ... I found it released a new non-beta version these days.

PS: I never used AutoKey ... And just research a little for my potential migration to linux from Windows+AHK

laoyb
  • 99
  • 2
  • 8
  • AutoKey is alive and fairly well, but we really do need one or more additional Python developers. We have an active community on our support [forums](https://github.com/autokey/autokey/wiki/Community). – Joe Feb 07 '23 at 21:48