Color me surprised, but this actually works and didn't feel nearly as janky as I thought it would :).
Download Macro(s): _Firefox line processing.kmmacros (19 KB)
Macro screenshot
Macro notes
- Macros are always disabled when imported into the Keyboard Maestro Editor.
- The user must ensure the macro is enabled.
- The user must also ensure the macro's parent macro-group is enabled.
System information
- macOS 13.6.4
- Keyboard Maestro v11.0.2
Though it does come with a number of caveats, as it's more a proof of concept than something that will just drop right into your Firefox macro (but it shouldn't be too hard to integrate).
One of the issues is that various editors respond differently to various word/letter selection shortcuts. I decided to use BBEdit (which has a free version, if you don't have it yet), as it has very robust support for such shortcuts. So that's Caveat #1: This macro requires BBEdit, and may not work without editing in other editors.
Relative to BBEdit, I didn't write any logic into this demo macro at all, which leads to the related BBEdit Caveat 1a, which is that you need an open blank BBEdit document before launching the demo. You could easily add some logic to handle this, but I didn't do it in the demo.
The way the macro works is that it takes the chunk of text (from Firefox in the "real world," from a variable in this demo), and reads it a line at a time. If the line doesn't contain a pipe symbol, then the line is just added to the "edited output" variable.
If it does contain a pipe, it's pasted into BBEdit, and the remaining characters from after the pipe until the end of the line are selected. The macro now waits for you to press the Escape key. Type whatever you want to edit the text, but don't hit Escape until you're done.
When Escape is pressed, the edited text is added to the variable containing the full edited text, and the loop repeats with the next line, until all lines have been processed. Somehow, I actually managed to write something that does select each and every "next pipe" with just one keystroke :).
Caveat #2 is that this macro is not ready to use in the real world. It assumes you have the text from Firefox already on the clipboard, and it doesn't try to paste the edited text back into Firefox at the end (but it does put it on the clipboard).
Caveat #3 is that it's only been tested in Keyboard Maestro v11, but it should work fine in 10 as well. It also may be somewhat computer speed dependent, so if things don't seem to be working, you might have to insert some Pause actions in various spots.
And finally, Caveat #4 is that the macro doesn't do much to clean up after itself. It leaves the BBEdit window open, for instance. I do, though, clean out the clipboard as it's being used, so it won't fill your clipboard history file :).
Overall, I'm pleasantly surprised at how this turned outβit feels pretty smooth to use, even though you're editing a line at a time. It will take some work to integrate into a total solution macro, but it should get you started (if you'd like to go this route).
-rob.