How Do I Add Line Numbers to End of Each Line? (useful to convert a table of contents to an alphabetical index)

Following up @tjluoma's comment, the reason I have pbpaste and pbcopy in my script is that I was sitting in front of an iPad when I wrote the answer and forgot that Keyboard Maestro has options for dealing with the clipboard as input and output. This would be the better way:

If you're not worried about the possibility of having a numbered blank line at the end, awk is shorter:

You could, of course, surround this step with Copy and Paste actions to get a macro that replaces the selected text with the line-numbered version of it.

2 Likes