Search and Replace Within Keyboard Maestro Itself

Over the years, I've written 106 macros that refer to various folders in Dropbox. I'm now leaving Dropbox. I want to change all the macros so they reference a new directory. I can not find a Find and Replace command in the Keyboard Maestro toolbar.

Does anybody have any tips? I'm thinking that I could open "/Users/will/Dropbox/Apps/Keyboard Maestro/Keyboard Maestro Macros.kmsync" in TextEdit and do a search and replace but this seems draconian.

There is no Search and Replace in the Keyboard Maestro editor.

Do not do this. Do not edit the .kmsync file.

If you really want to try something like this, instead:

  • Quit Keyboard Maestro Engine
  • Quit Keyboard Maestro
  • Edit the Keyboard Maestro Macros.plist. Carefully search and replace there.
  • Launch Keyboard Maestro. Make a change to the macros (so that it will sync to the other Mac).

And keep good backups!

I'd probably rather use AppleScript to find ⇢ get ⇢ munge ⇢ replace the XML of the given actions.

But I'd have to do some testing, before I'd endorse such a scheme...


Another thing to consider...

You're changing things around, and you might do so again – so you might want to bite-the-bullet and implement one or more global variables as anchors for your frequently used paths.

That way you can change the global variable once and change all the associated paths.


First of all, as @ccstone says, absolutely do put the path in a global variable, so you only have to change it in one place. A lot of us use the convention of prefixing the variable name with DND_ or DND__, which stands for "Do Not Delete" (in fond remembrance of @JMichaelTX).

I don't know if it would help to use my macro set KMET or not. You could do a search/replace using it, but probably only one macro at a time, so like I said, I don't know if it would be helpful or not.

Personally, I could write a JXA script to do the trick, but I wouldn't take the chance with someone else's macro library. (Not sure why I'm even mentioning that.)

Sometimes it's better to just bite the bullet and do it manually.


Thanks, you've all talked me down from trying something a bit foolish. @ccstone, your suggestion about global variables is what I needed. This is a 'Keyboard Maestro Best Practices' that I wish I'd followed from the beginning. @DanThomas I remember @JMichaelTX using DND_ as a variable prefix but I never caught on to the importance. Am I right in thinking that there is no special category of variable called "Global Variable" and it just a convention that a variable is set and left alone, hence the Do Not Delete?

[NOTE: This ended up becoming longer than I intended, so feel free to not read. Or stop somewhere along the way.]

It's the other way around. "In the beginning", there were only global variables. So any variable used in a macro sat around forever.

Eventually someone realized that having a lot of variables sitting around not being used actually slowed things down some (a small amount, but still). So we started a "best practice" of trying to always "delete" variables after using them.

We bugged @peternlewis to add Local variables, and IIRC, he said something about us not holding our breaths. I could be wrong. And then one day he announced a version with Local and Instance variables, and the world rejoiced. Well, a handful of us, anyway.

So now most of us "old hands" use Local and Instance variables exclusively, unless we really want something to hang around. You might expect to see nothing but "DND" global variables now if I looked at all my variables, but it's hard to go through and change everything.

So that's why I wrote the Variable Inspector Prompt, which lets me sort variables by size, so I can at least find the big ones and change their macros or just delete them.

Sheesh, I can pontificate sometimes, can't I? :smile:


@DanThomas thanks for your detailed history of variables and the pointer to VIP.
I wish I had this background as a beginner. My variable collection would be shorter and more meaningful. I fault myself for being so excited with Keyboard Maestro at the beginning that I sort of, but not really, read the quick start instructions. There are benefits to variable hygiene and mine is not been good.


Same with all of us. KM is a HUGE undertaking, so worrying about little things like taking care of variables isn't even near the top of the list. Any of us who have managed to not just give up with the sheer overwhelming enormity of KM deserve to give ourselves a break for not sweating the small stuff.