I’ve been using Ubuntu for a long time and have been lamenting the sad state of autokey and it’s relationship with Firefox and Thunderbird. Autokey is also a little more than I even need. I just want a quick way to expand a text snippet into a longer chunk of text. For example, I want to type
sig and have it expand into my complete email signature – not matter what browser or email client I’m using. So I put together this tiny little script to do just that. Here’s how it works.
There are a variety of different little things I tend to type over and over. I answer support questions for Cart66, the WordPress Ecommerce Plugin and there are some common questions that tend to come up on a regular basis. So I have saved answers for those common questions. Another example is my contact information. If I am sending a personal email I might put a different email signature with my personal contact information as my email signature. If I am sending a business email, I’ll use a different signature. I also do a lot of coding and there are various code snippets I use repeatedly.
There are browser add-ons that can do text snippet expansions. One of the best ones I’ve found is Auto Text Expander for Google Chrome another one is My Words for Firefox. Of course there’s also Autokey for Ubuntu, but it doesn’t work in Firefox or Thunderbird. I just wanted a simple, centralized tool that worked with everything where I could just type a little abbreviation and have it expand into whatever larger text block I needed regardless of what app I happen to be in. There is Snippy which uses dmenu to do a fairly similar thing to what Texpander does. But I prefer using zenity so I can just type in whatever abbreviation I need rather than using dmenu to select the abbreviation.
So, I wrote this really small bash script which you can assign to a keyboard shortcut. When run, it will prompt you for an abbreviation using zenity. Then paste the contents of the file in your
~/.texpander directory matching the abbreviations you just entered. If you have your email signature in a file called
~/.texpander/sig.txt you would enter the abbreviation
sig when zenity prompts you. It looks like this.
To use Texpander:
- Start writing an email to somebody (or start editing any document)
- Put your cursor where you want your email signature to be pasted
ctrl+space(or whatever keyboard shortcut you set up)
- A zenity window will appear asking for your abbreviation
- Type in
sigand hit Enter (or click “OK”)
- The contents of
~/.texpander/sig.txtis pasted into your document
The terminal works a little differently from other GUI apps in that you have to type
ctrl+shift+v to paste stuff. In texpander.sh there is a check to see if the active window is a terminal. If so, it will paste using
ctrl+shift+v if not then it will paste normally as
I’m really happy to see all the comments and also really appreciate the contributions on github. I have gotten a couple questions about how to create a custom keyboard shortcut to launch Texpander. I’m on Ubuntu 16.04 and all you have to do is…
Launch the keyboard preferences (part of System Preferences). I just fire Dash by pressing the
super key and then type
keyboard like this.
Then you’ll see the keyboard preferences window and you can create a custom shortcut, like this:
When you click the ( + ) a little window will open where you can name the shortcut and specify the command to run. The command is just the absolute path to the location where you installed
It might not be immediately obvious how to actually set the keys that trigger the shortcut. All you do is click on the window where the key sequence is located.
Installation details and more information about how to use Texpander is available on github.