Inserting a period between number characters in selected text (or entire document) in a markdown file

Hi folks

I regularly transcribe chapter references from a technical manual which is a pain to do because of the periods/full-stops that must be individually typed between the numbers (subsections) in each reference.

I am trying to create an automation that will either:

  • Take the selected text (always numeric characters) and add a period between the numbers e.g. when the action is performed on 312812 it will output as 3.1.2.8.1.2, or

  • Parse a markdown document and perform this action on any numeric string in the text.

The output may be required in a different format for numbers 10 and above e.g. 6.7.3.15.8, where 15 must not be outputted as 1.5. Perhaps this could be entered as 673 15 8 to delineate this element so the output is correct.

Ideally this would be available system wide rather than in a particular application.

Any suggestions would be welcome!

Many thanks.
Marcus

Do you have any automation tools or languages that you would prefer to utilise?

Which option (selected text or Markdown file) would be your preferred option? There are potentially different tools and approaches to support these two different options.

If the former option, what is your editor of choice?

Thanks @sylumer

For quick text actions I generally use PopClip extensions or trigger an AppleScript script from the services menu (one of Brett Terpstra’s). I’m a Drafts user as well - I write in Drafts and in DEVONthink.

I think selected text might be the best option as the relevant text is usually in the same location in each document and the whole document approach might cause issues if there are other numbers in the text e.g. quantities, that are not the subject of the action.

Okay, the services menu is probably easiest to whip something up for. Here are a couple of Automator workflow actions (Quick Actions/Services) that do what you have described above using some command line substitutions steps, and a bit of Automator text replacement for selected text.

Both of the workflows are ZIP’d and are not code signed.

Please do examine the scripts prior to running them to ensure you are happy that they are not doing anything untoward.

They should just be passing the selected text into some stream editor steps that carry out regular expression based text substitutions.

Hope that helps.

Thank you very much @sylumer, I really appreciate it.

This will save endless hours of slowly typing numberer-period-number…n

The first action works perfectly.


I was probably unclear about what is needed in the second action though.

For example:

Input: 673 15 8
Desired output: 6.7.3.15.8

I appreciate your time and I won’t impose any further. If I can figure out the RegEx I’ll post it here in case anyone else can use it too.

If you re-download that workflow from the earlier link it will now produced the revised output.

If I had been thinking straight I would have realised. I’m going to blame my massively pollen congested head for that oversight.

Thank you so much again, this is incredibly useful for me :grinning: :pray:

Much appreciated especially considering your congestion, which I can relate to!