I wrote a macOS Service way back in 2012 that I’ve used ever since. It allows you to write some text and include special placeholders, then select it and repeat the text, incrementing the placeholders with each iteration. I last updated it in 2014 with better indentation handling and zero-padding, but otherwise it hasn’t seen many changes. Until this morning.

Numeric

Originally the Increment Templated Service only handled numeric incrementation. It still does, but I changed the syntax to 0..5 instead of 0,5. You’ll see why in a second. Since you’re likely unfamiliar with the original (given its age), I’ll demonstrate what it does. Start with a block of text like this:

This is paragraph ##1..3##. The next paragraph will be paragraph ##x+1##.

The ##X..X## specifies a start and end count for the iteration. The ##x## is a placeholder that inserts the current element again and optionally performs math operations (+, -, *, /, %) on it. So the result of running the Service on the above text is:

This is paragraph 1. The next paragraph will be paragraph 2.
This is paragraph 2. The next paragraph will be paragraph 3.
This is paragraph 3. The next paragraph will be paragraph 4.

You can use ##x## to repeat the current item as is. This can be handy when writing code, simulating a bit of Emmet action:

.element-##1..3## {
    text-indent: ##x*10##px;
}

Produces:

.element-1 {
    text-indent: 10px;
}
.element-2 {
    text-indent: 20px;
}
.element-3 {
    text-indent: 30px;
}

Increments

You can also now specify an increment the way you would with the seq command. Just add a third number in the middle: ##2..2..10## gives you 2, 4, 6, 8, 10.

##5..5..25## jumps by five

Renders to:

5 jumps by five
10 jumps by five
15 jumps by five
20 jumps by five
25 jumps by five

Arrays

Another big change is that Increment Templated now handles arrays of strings or numbers. Similar to glob expansion in the shell, you can use comma-separated items in the placeholder which are then enumerated. So you can now do this:

Hello ##Mother,Father,Sister,Brother##.

And get this:

Hello Mother.
Hello Father.
Hello Sister.
Hello Brother.

When using arrays you can still repeat the current item with a ##x## placeholder, but you can’t modify it. You do, however, have the index of the current item available as ##i##, which is zero-based (the first element is 0), and can have math operations performed on it.

##First,Second## is number ##i+1##
First is number 1
Second is number 2

PopClip

I also made a PopClip version of this which is now available as part of Brett’s PopClip Extensions. It works the same way, just puts the Service on a handy button that only shows up when the selected text contains template syntax.

Increment Templated Service v3.0.2

Repeats a selected block of text a specified number of times, replacing placeholders with the count of the current item with variable start and end numbers.

Published 07/01/12.

Updated 02/06/23. Changelog

DonateMore info…