5

How do I setup AutoKey to get the following result?

  1. I type a word like ubu in a text editor
  2. A window opens with the suggestion ubuntu
  3. I can select ubuntu through TAB-key
  4. ubu gets replaced with ubuntu
DK Bose
  • 42,548
  • 23
  • 127
  • 221
Tom
  • 187
  • 1
    Have you looked at texpander? It requires a couple of small packages to be installed if you don't already have them. Assuming you have created a list of often-used phrases, when you invoke texpander by a shortcut combo you set up, a zenity window opens and you can select the phrase you want to install. In that sense, it's different than Autokey which, I assume will only provide hits related to ubu (in your example). – DK Bose Sep 13 '18 at 10:56
  • Thanks for your suggestion. Does it recommend words or filter words in that zenity window based on what I typed? – Tom Sep 13 '18 at 12:18
  • 1
    You need to create a folder, ~/.texpander, and put in each phrase/string you may need to insert into a document into separate text files. Then, when you need to insert a particular phrase/string, press the shortcut to run texpander, I use Ctrl+tilde, the zenity window appears: if you've been cunning enough to name your text files in ~/.texpander, typing one or two letters is enough to select the phrase/string you want. Pressing enter inserts the chosen phrase/string. I like it because it runs only when needed unlink Autokey. – DK Bose Sep 13 '18 at 13:02
  • The last sentence should read: I like it because it runs only when needed unlike Autokey. – DK Bose Sep 13 '18 at 13:30
  • I tried multiple times to get Texpander to work. It is really frustrating. The zenity window does not show up – Tom Sep 13 '18 at 16:17
  • 1
    I took a chance and posted. Note the use of xsel because that's what the script uses instead of xclip. – DK Bose Sep 13 '18 at 17:06
  • 1
    If you're on 17.10, it's possible you can't install the additional packages needed for Texpander to work! – DK Bose Sep 14 '18 at 12:02

1 Answers1

1

Note: this may not work in a Wayland session!

Texpander:

Texpander is a simple text expander for Linux. It is sort of like Autokey, except it works off of text files that you put in your ~/.texpander directory. Texpander is a bash script that uses xclip, xdotool, and zenity to let you type an abbreviation for something and it expands to whatever you have in the matching text file.

Download the .zip file and extract the contents.

Copy texpander.sh over to ~/bin. Make it executable.

Use your distro's method to assign Ctrl+Shift+~, for example, to texpander.sh. (Note that ~/bin should be in your $PATH.)

Install xsel, not xclip, and xdotool using sudo apt install.

Create a folder ~/.texpander.

In that folder, create the following three files: au.txt, off-topic.txt and os.txt with the following contents:

au.txt

Welcome to Ask Ubuntu!

off-topic.txt

Questions about distros other than Ubuntu or other official flavors are off-topic here.

os.txt

OS: Ubuntu 18.04.1 LTS

Open a text editor and press the assigned shortcut to launch texpander.sh. You'll get a Zenity window like this:

Texpander choices

If you have a longer list, there'll be a handy scrollbar or just type the first letter of a listed item to jump down the list to that item.

Select the one you want and press Enter or click OK.

A longer list with scrollbars

Troubleshooting: If things don't work, try increasing the sleep values in lines 45 and 61 of texpander.sh. xdotool on older machines may benefit.

DK Bose
  • 42,548
  • 23
  • 127
  • 221
  • Now it works, thank you very much for the tutorial. The only thing I'm missing at this point is that the window pops up as soon as a phrase gets detected. A workfow like this: I type -->Stack -->Window pops out -->Highlights Stackexchange -->I just need to press enter -->Stack gets replaced with Stackexchange. Could that be added to TexPander? – Tom Sep 15 '18 at 13:19
  • 1
    I would think not. That would require Texpander to be running constantly to monitor the keys pressed by the user. That's partly why AutoKey is constantly using resources. Texpander runs only when invoked by the shortcut key you use to call it. – DK Bose Sep 15 '18 at 13:29