Home-made text expander

Issues and / or general discussion relating to Puppy

Moderator: Forum moderators

Post Reply
doomcur

Home-made text expander

Post by doomcur »

Home-made text expander

Instead of a question looking for an answer, here's an answer looking for a question.

Having failed to find a text expander that I like and that's available for Puppy Linux, I decided to make my own. This is what I'm using at the moment. Other versions are of course possible.

It's just a simple script, although to use it you'll need the extra Bash tools xdotool and xsel.

If you like this little gadget, feel free to use it, modify it or do anything else you like with it. If you don't like it, you can always carve it on a stick and throw it for the dog to fetch.

Code:
___________________

Code: Select all

#!/bin/sh
sleep 0.3;
xdotool key Shift+0xff51;
xdotool key Shift+0xff51;
xdotool key Shift+0xff51;
sleep 0.05;
xdotool key Ctrl+x;
sleep 0.05;
short=`xsel -ob`;
sleep 0.05;

if [ $short == exa ]
then
echo -n 'example' | xsel -ib;
xdotool key Ctrl+v;
fi

___________________

To use

1. Install xdotool and xsel if not already installed. They seem to be widely available.

2. Copy the code into a text file (copy exactly or it may not work).

3. Create extra if statements with whatever short and long strings you want, by copying and pasting the example given and then changing the strings.

4. Save the file as anynameyoulike.sh

5. Open properties and make the file executable.

6. Set up a keyboard shortcut.

You're ready to expand.
..........................................

Basic Notes (more information can be supplied if anyone asks)

In this version of the expander, every short string has to have exactly three characters. A short string can be set up in the code with only one or two characters, but (unless it's at the very beginning of a file) you'll need to remember to type an extra character space or two in front of it when using it.

When you're in the middle of typing something and you run the script, it does the following:
1. selects the first three characters it finds as it works back from the insertion point
2. cuts them (so now they're on the clipboard)
3. looks in the code and finds the if statement containing the short string (the three characters it's just copied)
4. then inserts the longer string from the same if statement.

Most or all text delimiters, other than a character space, can be used in the short string in any position, and the expander works correctly after a character other than a text delimiter. This is the advantage of using a fixed number of characters in the short string -- text delimiters almost never confuse matters.

The short string doesn't have to be the first three characters of the replacement string, although it can be. In fact it doesn't have to resemble the longer string at all, although in many cases it'll be easier to remember if it does.

If your computer's a bit slow, you may need to make the delays in the code (where it says 'sleep') a little longer.

Last edited by rockedge on Sun Aug 20, 2023 3:29 pm, edited 1 time in total.
Reason: added code block for the script
Post Reply

Return to “Users”