Inverting Names with Copy and Paste from One App to Another

Hello,

I often need to copy and paste names from one app to another, and the names need to be inverted when pasted. So, for example, John Smith needs to become Smith, John.

Is there a way to create a macro for this? How much of this can the macro do? The most useful portion for me would be to invert the name. Can the macro also automatically paste in the appropriate app?

Thank you,

Stephen

The Super Swap macro will swap two selected words. It won't get rid of or add a comma but you can modify it to suit your needs.

I'm no KM Guru, but I'm willing to share my macro and welcome any feedback!

Copy Selected Text To Clipboard As Last- First Name & Reverse.kmmacros (28 KB)

Thank you for the help.

If I am reading yours correctly, is the assumption that the name already has a comma in it? So it would be reversing:

John, Smith to Smith, John?

For the names I am working with, the comma is not present and would need to be added.

Thank you. The swap is working for me, and yes, I would like to add a comma in there.

Super Swap won't add a comma. It just swaps things within a selection.

You could write action to move left a word (Control + Left), left a character (Left) and insert a comma, though. Like this macro:

Add a comma.kmmacros (2.4 KB)

This simple macro should do the job, or at least provide an example you can use.

MACRO:   Convert FirstNme LastName to LastName, FirstName [Example]

**Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/4/0/40d8218ffb97af08ff9e5be3494dedef079f0377.kmmacros">Convert FirstNme LastName to LastName- FirstName [Example].kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


---


![image|605x795](upload://uobxeZ7AZGwTsch8YvOeLFhSaQS.png) 

Questions?

Stephen_Ullstrom,

Not exactly. I mostly use the macro I provided to convert employee names from an Excel file where they are stored as 'Lastname[comma]Firstname' to copy and paste as 'Firstname[space]Lastname' elsewhere. However, where I have the name selected as 'Firstname[space]Lastname' and I need it as 'Lastname[comma]Firstname', the same macro is used with the other trigger (i.e. the last name moves in the direction of the > or <).

So:
'First Name[space]Last Name' to 'Last Name[comma][space]First Name'
John Smith would be replaced with Smith, John
or
'Last Name[comma][space]First Name' to 'First Name[space]Last Name'
Smith, John would be replaced with John Smith

Like this (same hotkey does either fix)?

Swap Names in Selection with/without Commas Macro (v9.0.3)

Swap Names in Selection with-without Commas.kmmacros (2.7 KB)

1 Like

I don't know perl, but I can incorporate the idea!

If you copy the names each individually, then a very useful general purpose macro is Paste Previous, just:

image

(using whatever hot key you want).

That way if you copy select John, Command-C, select Smith, Command-C, and then in the target, Paste Previous “, ” Paste Previous.

In fact, that's the whole macro. You don't have to figure out the Perl. Just select the two names, press Option + Comma and it will swap them, adding a comma if necessary.

You can do this with Keyboard Maestro actions, but I just love the clarity of a simple Perl script.