Replace comma by Enter

Hi all,

Total novice here trying out Keyboard Maestro before ultimately purchasing. I am trying to create an action that replaces a comma plus a space by an Enter/Return. I have managed to copy the text, open Microsoft Word, paste the text, but I can't seem to find out how to remove the comma and space, and then replace it by an Enter/Return. My idea is to then copy the result, open my label printer software and paste the text, so that it will be ready to print.

Any suggestion on how to do that? If you know of a more efficient way to do this without opening a text processing application, that would also be very welcome.

Welcome to the KM Forum.

It seems like what you're trying to do is quite straightforward. But to be sure, please provide further information. For example:

  1. Where do you get the original text from? An app?
  2. Provide an example of the text that you're starting with.
  3. Show how you want that text to appear after the transformation and before you paste it into your printer software.
  4. Which printer software are you using?

This will help someone here come up with a good answer for you!

Thank you very much for your quick and kind response!

The text will be from a PDF file, selection of what will have to be copied is already made manually.

Input format is like:
Mr John Smith, 132 Chapel Hill, Heswall, Bournemouth, BH1 1AA, United Kingdom

Output format should be:
Mr John Smith
132 Chapel Hill
United Kingdom

Printer software is called Dymo Label.

Here's a demo macro for you to explore. The two red-coloured actions are there just for when I was testing so you can just delete them.

The macro in essence takes the clipboard contents and uses a regular expression replacement action to perform the reformatting as you required, leaving the result in the clipboard - ready to be pasted into your label software.

To run the macro, just enable it. I've assign a hot key of F5 to it - you can change that to something that suits you better.

You could extend the macro to do a Copy at the start (assuming you have some text selected already) and a Paste at the end to get the reformatted text into your label s/w. But I leave that to you.

Hopefully, this will point you in the right direction but in any case let us know how you get on!

Download Macro(s): Test Replace comma by Enter.kmmacros (3.2 KB)


Keyboard Maestro Export

  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

Thank you so much for your help. I've come to realise that I need some more reading and practice before really getting started. I understand the basics and was hoping to learn along the way, but it probably doesn't help that I have no programming experience either.

I will bookmark this page and get back to it once I understand macros and all KM's features a little bit better. I'm pretty sure I will then be able to solve my issue. Thank you once again.

1 Like

Hi and welcome to the forum! :wave:t3:

You can use this version of @tiffle's macro, without any previous KM experience.

  • Select a single-line address in Word.
  • Hit F5.

Have fun!

Replace ", " with Enter.kmmacros (20 KB)

Macro screenshot

1 Like

Thank you for your response. The single line address is in a PDF file, not in Word. I only used Word as a text processor in order to change the formatting, since I didn't know about the regular expression action that doesn't require a text processor. After copying, the text should be pasted in Dymo Label software.

The macro as you sent it does not seem to do anything for me. It does not even copy the selected text (when I paste manually, some previously copied text is pasted).

In order to paste something in Dymo Label, I guess a step 'Activate Dymo' and then a mouse click in the text field are required before pasting. But when I add those steps, still nothing happens.