MACRO: Automatically highlight repeated selections of text in 11 apps

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

highlight_sample

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.

5 Likes

Wonderful. And creative. This is the exact type of problem that KM was designed to solve, in my opinion. May I ask a few questions?

  1. I tried this feature using the "Mouse Keys" option in System Settings, which is a mouse emulator using the keyboard, but I was not able to get it to work (at least not with Pages.) Do you know what I might be doing wrong? I like to have keyboard alternatives for all my macros.
  2. Would this utility also work with a user who uses a trackpad instead of a mouse? I don't have a trackpad here today to test with.
  3. Would this utility work with a Stream Deck as the trigger to turn it on?
  4. Could a mouse gesture (or USB capable mouse button) be used as the trigger?

I had a theory that it was trigger related, so I tested my theory, and it worked: If you change the two mouse-button loop triggers to watch for the keypad's 5 up and down instead, it works:

Move the mouse to the right spot with the other keypad keys, then press and hold 5 and move the mouse with the other keys; release 5, and the selection gets highlightreed. Repeat as necessary, and it keeps working until you cancel the macro.

Yes, it was actually originally written for someone who uses a trackpad, and it works fine on my laptop.

Seems the answer is yes, as this setup worked to enable the highlighter:

You could use a different button to turn it off by just having it send any given modifier key. I tested that, and it works. What's much more complicated, and I couldn't figure out how to do in a few minutes of testing, is to use the same SD button to toggle the highlighter on and off. The problem is that when the highlighter is on, the macro is in a loop, watching for modifier keys, so the SD buttons don't do anything even if assigned to run a macro.

There might be some way around this, but what it is isn't clear to me, so I'll give up on that aspect of it for now :). But the basics of toggling the macro on and off via SD work fine.

Should work fine, and did in a brief test:

You can't watch for a gesture to disable the highlighter, though, as that's not one of the options available in the Until action.

-rob.

1 Like

absolutely brillant. Huge improvement in workflow.