Replace text

Can I input to this text to Keyboard Maestro:

RK, MS, L., GP, CS

and get Keyboard Maestro to replace this inputted text with this:

Redshank, Mute Swan, Lapwing, Golden Plover, Common Sandpiper

Yes. Each one is a simple macro with Typed String trigger like "RK" and action Insert Text by Typing. Make sure the trigger is case sensitive. The trigger should include the . for "L." (otherwise a trigger like "LR" would first the L trigger first).

Probably you want to put all the macros in a macro group that you activate/deactivate manually. I would likely have it show as a palette so you can easily tell whether it is active currently, something like this:

I use that palette for a similar set of Typed String triggers for naming faces in iPhoto.

Thanks Peter. However, your suggestion isn’t what I’m after here.

Say I have this string:

RK, MS, L., GP, RK, MS, L., GP, CS, RK, MS, L., GP, CS, RK, MS, L., GP, CS

I want to feed this 1 string into Keyboard Maestro using 1 trigger, and have Keyboard Maestro spit back out this string:

Redshank, Mute Swan, Lapwing, Golden Plover, Redshank, Mute Swan, Lapwing, Golden Plover, Redshank, Mute Swan, Lapwing, Golden Plover, Redshank, Mute Swan, Lapwing, Golden Plover

Does that make sense?

Have you tried using a group of search-and-replace Actions in a single KMacro? I’ve done similar: worked well; easy to add entries. Somewhat like a carpentry jig: feels tedious to set up, but the saved time brings a smile.

Something like:

  • Copy selection
  • Search clipboard for “RK”, replace with “Redshank”
  • Search clipboard for “MS”, replace with “Mute Swan”
  • &c
  • &c
  • &c
  • Paste

Since I have had occasional problems with repeated Clipboard operations, I would set the copied text to a KM Variable (e.g.: %Variable%String%) and use the Action “Search and Replace Variable” repeatedly. On your system that may prove unnecessary.

Works well thanks.

Keyboard Maestro will do this sort of thing very well, although Kirby is right – multiple find/replace operations are better done on a variable rather than the clipboard.

Generally I’ll do this sort of thing with the Satimage.osax AppleScript Extension.

------------------------------------------------------------
# Satimage.osax MUST be installed.
------------------------------------------------------------
set _text to "RK, MS, L., GP, RK, MS, L., GP, CS, RK, MS, L., GP, CS, RK, MS, L., GP, CS"

set findPatterns to items 2 thru -2 of {"", ¬
  "\\bGP\\b", ¬
  "\\bL\\.", ¬
  "\\bMS\\b", ¬
  "\\bRK\\b", ¬
  ""}

set replacePatterns to items 2 thru -2 of {"", ¬
  "Golden Plover", ¬
  "Lapwing", ¬
  "Mute Swan", ¬
  "Redshank", ¬
  ""}

set _text to change findPatterns into replacePatterns in _text with case sensitive and regexp

-Chris