A few days back, @Ronald asked about highlighting text with a modifier key instead of a keyboard shortcut. At first, I didn't understand what he was asking for…then I really didn't think it would be doable: He wanted a macro that would let him just click and drag his mouse, over and over again, and use his chosen app's Highlight Text feature to automatically highlight the text.
But I was surprised when I had a basic but working version done relatively quickly. It turned out to be relatively simple to write, though it took a while to get it to handle the variety of different apps that offer highlighting. Here's how the macro looks in action with Bear (a Markdown text editor) and Preview (with a PDF):
Universal Highlighter in action
But Universal Highlighter works with more than just two apps. It currently works with 11 different apps:
Acrobat Pro • Acrobat Reader • Bear • Highlights • iㅤA Writer • Microsoft Word • Pages •
PDF Expert • Preview • Scrivener • Ulysses
If you'd like to see it at work in 10 of those 11 (I don't have Acrobat Pro), here's a video with all 10 of them going.
You can enable a number of visual indicators to remind you the macro is running: A cycling progress bar, a very bright HTML reminder box, and the macro can hide all the other windows while it's operating. Here's what the visual indicators look like:
You can have anywhere from none to all of these visual indicators; I prefer the HTML warning box with the hiding of other apps; it's very clean.
The macro is activated with a double-tap of a modifier key on your keyboard, then stays active until you tap any modifier key one time. While it's active, any selected text will be highlighted if you're in a supported app. And it is so much nicer to use to just be able to drag-select and repeat without going to the keyboard all the time.
__ Universal Highlighter Macros.kmmacros (598 KB)
How to use
Because this macro is triggered with a USB Device Key trigger, you need to set the trigger for your own hardware. You'll see a big red box that explains exactly what to do when you look a the first macro in the group, 0 Universal Highlighter
.
The second macro, 1 Options
, contains the on/off settings for each of the visual cue options, as well as one for Microsoft Word: If you want to use the macro with Word, you have to set up a keyboard shortcut first. The documentation in the macro covers both options and setting up Word.
How it works
The basic macro is simple but elegant in how it tracks mouse activity to let the macro keep running. An outer "Until" loop runs until one of the modifier keys is tapped, signaling the end of the macro. Within the outer loop, there's another Until loop that does absolutely nothing except sit there until the mouse button is pressed.
Once that's detected, a third Until loop starts, looping until the mouse button is released, signaling the end of the selection. When that loop exits, it checks to make sure there's a selection (by looking for an active Copy menu), then runs the proper 'highlight this text' command for the frontmost app.
With that done, the outer loop is in charge again, waiting for the cancellation key while the first inner loop watches for a mouse press.
This basic structure could be very useful for other macros that need to interact with the user while still continuing to run; I may post a general version at some point demonstrating how to do that.
But if you need to highlight a lot of text often, you'll probably find this macro to be a great time saver. Thanks to @Ronald for the initial question and feedback on earlier iterations, and to @_jims for his feedback on earlier builds.
-rob.