[KM8] Find and Replace Text in Actions

A macro that takes advantage of the new AppleScript-based XML editing abilities in KM8 to find and replace any given string of text in actions.

##Example
Start with something like this:

Run this macro twice to perform two find and replace operations:

End up with this:

##Download
Find and Replace Text in Actions.kmmacros (6.0 KB)

##Notes
This macro requires both Keyboard Maestro 8+ and the Satimage osax to function. The Satimage osax can be downloaded here: http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html

If the macro is not in editing mode, changed text will not immediately appear once the macro has run. Either begin editing the macro, or select another macro and switch back to the one you ran this macro on to view the results.

Please also note that while my initial tests have been successful, this macro has not been thoroughly tested and may cause unexpected results. I suggest making a copy of any important macros you wish to use this on before running it. Remember that you can also use ⌘Z after using this macro to revert the macro to its original state.

@gglick, and all:

:exclamation: You should be aware of two issues:

  1. Changing ALL text in the XML string could be dangerous, and result in an unusable macro, since you might inadvertently change some key strings in the XML.
  • So, I personally would not try to change any text other than that which I am very sure is unique text created by me, like an obviously unique variable name like "CMC__FootNoteNumber".
    .
  1. This will change only those parts of Actions that are plain text.
  • It will not change rich text areas, like in Comments and Display Window.
  • I have documented this here.

Thanks for the heads-up, @JMichaelTX! I did try to outline the risks in my notes, but you’re right that it’s unnecessarily dangerous as-is. When I get a chance I’ll see if I can’t find a way to restrict it to anything in-between <string></string>, which should greatly reduce the danger.

Thanks for reminding me of the rich text aspect too! I’ll also see if I can’t incorporate your/Shane Stanley’s conversion script to have the macro search rich text as well (I’m not very confident about figuring out how to convert searched rich text back into rich text after it’s been converted to plain, since I still have little experience with AppleScript and zero with Objective-C or even ASObjC, but I figure one step at a time :slightly_smiling_face:)