Hello! KM is such an invaluable tool, I love this software and I'm sure what I want to do is achievable. But my macro does not work.
What I want to do: I've got a string in my clipboard and I've selected a (similar) string in a browser form field. Now I want to replace all occurrences (there is always more than one) of the selected string with the string in my clipboard. I've done something similar before with AutoHotkey on Windows, and the way I did that there was to copy the different strings to temporary clipboards, then select the whole form content, search for the old string and replace that with 'new'. My approach with KM was this:
But this just does not work. And I think the reason is that the string to search for cannot be a variable but I tried it that way? Can someone point me in the right direction, please? I think this is a quite simple task, but can't see the forest for the trees. Thank you!
Just noticed two errors in my macro: 'ContentToReplace' shall be replaced with the value in 'temporary' and the output of Search and Replace should be the System clipboard from where the content is pasted:
But: the macro still does not do what I want it to do.
I don't know why this might help, but what happens if you copy the form contents from the clipboard to a KM variable, do the search and replace on the variable, then put the variable back on the clipboard?
I had a similar but different issue in the past, and that resolved it. (And as it works, I never bothered trying to figure out why the other method didn't work—it could be related to the formatting of the text on the clipboard, perhaps.)
It took me a bit to have a look into that. Did I understand that correctly?:
It's not working. "Search and Replace Variable" stays empty. I think "using String" does not expect a variable, and that's why. Or is there another function I have overlooked?
Your second copy step copies to a named clipboard—
ContentToReplace—not to a variable. But your Search and Replace is searching a Variable. Change that to a Named Clipboard (or change the Copy to copy to a variable) and see what happens.
I see, thank you. Now I went through several iterations of the macro and finally it works as expected. I made the mistake you mentioned above (and probably a few others) but also did not notice that the macro was not made available in all applications/windows. This is my working result - probably not the most beautiful/efficient way to accomplish the task, but I don't mind that much
Thanks again, Rob!
Glad it's working for you—and that's the only thing that really matters: If the macro works for you, then that's better than a macro that might be better designed but doesn't work :).
I will point out one thing:
You copy the system clipboard to a named clipboard, then copy the named clipboard to a variable. Unless you need that named clipboard elsewhere in the macro, this is an extra step. Just copy the system clipboard directly to the variable.
Thanks for pointing that out, you are right! I'll change that.