Text of specified length with TextExpander

I saw a tutorial recently where the instructor was writing things like lorem8 in his editor, which would then expand to eight words of lorem ipsum text. He was using Atom, but I’m wondering if there’s a way to do this with TextExpander so it would be available across apps. Anyone have ideas?

1 Like

I have standard Lorem Ipsum textexpander snippets, but you could make those as long as you want. So creating a Lorem8 to expand to 8 words from Lorem Ipsum is easy.

But I guess that’s not your point?

Either create a TE snippet that exactly matches the output you want, as the instructor likely had, or create a snippet that then prompts you for how many words and then uses scripting to extract that many words from your sample lorem ipsum text, and insert them.

The former is the fastest, but requires more menial set-up. The latter is more complex and is multi-step to trigger, but gives you a greater scope of how many words you want to actually insert.

Whilst the latter is nerdier, the former is probably more functional for most users in most cases; though of course, you could implement both just because :nerd_face:

I quickly put together an example of the latter in case it is of use. Not thoroughly tested, but it should be functional.

TextExpander Javascript: Enter number of words to return

let strLorem = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eget neque nec ipsum ultrices ultricies et a tellus. Quisque molestie leo purus, vitae imperdiet orci. Pellentesque mauris turpis, eleifend at lobortis eget, lacinia vitae lectus. Praesent nec elit nunc, nec molestie nisl. Suspendisse facilisis mi vitae nisi sollicitudin ut imperdiet elit rhoncus. Etiam interdum cursus purus, ut pharetra enim adipiscing faucibus. Nulla malesuada aliquam sollicitudin. Integer imperdiet accumsan iaculis. Quisque fermentum, lorem condimentum convallis auctor, erat sapien egestas sem, et rutrum diam nunc eu mauris. Etiam quis urna et velit euismod mollis. Morbi congue orci eu purus facilisis id hendrerit dui malesuada. Nulla nisi nisl, scelerisque eu euismod faucibus, scelerisque et lectus. Maecenas consectetur tristique justo ut venenatis. Nulla facilisi.`;


Apparently I am so nerdy (or dumb) that it didn’t even occur to me to just use exact-match snippets for the various numbers of words of lorem ipsum. I think @sylumer’s solution has me about 80% there. It basically does what I want although the number of words produced doesn’t quite correspond to the number entered. I’m going to play around with it a little and will post anything useful I come up with.

This works pretty well. Many thanks to @sylumer for the examples of TextExpander’s fill-in syntax.

use strict;
my $count = %filltext:name=Words%;

my $lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut posuere dolor nisl, nec suscipit elit ultrices sit amet. Nulla nec lectus porta purus imperdiet venenatis a et lacus. Integer posuere mi sed ante molestie interdum.';

my @words = split(/\s/, $lorem);

my $i = 0;
foreach my $w (@words) {
	$w .= ' ';
	print $w unless $i >= $count;
1 Like