Find+Replace in Selection; Restore Selection Macro (v11.0.4)

Sometimes you want to find and replace in selected text only. And after the replacement, you want the modified text to be selected again. E.g. because you want to run another Find/Replace action:

Image-001094

This macro is a first draft for that task. The checkboxes aren’t functional yet.

Suggestions are very welcome.

Find+Replace in Selection; Restore Selection Macro (v11.0.4)

Find+Replace in Selection; Restore Selection.kmmacros (5.0 KB)

Does the part of your macro that you wrote work? (If you had uploaded your macro, I could have checked if it works.) If it works, the only suggestion I have is that you can shorten your code a little bit by doing this:

1 Like

Is this specifically for BBEdit, or for text editors in general?

For BBEdit -- and assuming a macro is actually more efficient than just using the normal Find dialog -- you can do this with AppleScript:

replace findStr using replaceStr searching in its window's selection options {case sensitive:caseSwitch, match words:wholeSwitch}

So:

Find+Replace in Selection, Keeping Selection (BBEdit only).kmmacros (4.1 KB)

1 Like

It’s meant for all apps where I can edit text, for instance BBEdit, Safari, Airmail, CafeTran Espresso, etc.

For CafeTran Espresso I’ll have to investigate how the selection “collapses” when pasting text. If I remember correctly, the behavior is different from native macOS apps.

Thanks for your script, I’m sure that It’ll be of use one day.

1 Like