Search and Replace Action using variables

Search and Replace Action using variables

The example comes from the Help section for the Search and Replace functions and it works fine (disabled action). If however I modify it to send the search and replace strings via variables it does not… sending the search string by variable works but NOT the replace string. My question is why not and /or what am I doing wrong

Search and Replace.kmactions (718 B)

I will try out your macro, but I have to retype your macro, because you accidentally uploaded only a single action, not your entire macro. So it will slow me down a bit. Do you know how to fix that?

I’m sorry about that. How do I ensure that the whole macro is uploaded?

I think I found the answer in the Help page for the Search action. It says:

Note that you can use tokens in the replace field (eg %Variable%Whatever%), but that when those tokens are expanded, the contents will themselves not be further expanded, so, for example you could not have a variable that contains $1 and expect that to be replaced by a the corresponding capture group. You could use an AppleScript like this:

I think you should read those instructions carefully. I don’t fully understand it.

I think you are supposed to click on a macro in the macro column, rather than an action in the macro window, prior to click on the File/Share/Forum menu item.

1 Like

Thanks for your help. I somehow missed that last paragraph which explains why I can’t do it

Have a look at this, it may help you Subroutine to Perform Search/Replace Using Variable Patterns

1 Like