I spend a lot of time in Messages in macOS, and one of its newer features is something called link previews, as seen at the right side of this text block.
While these previews can occasionally be useful, most of the time, they’re just annoying: I’m talking with people I know, and we trust the links we send each other, so the preview is superfluous. Plus it makes it nearly impossible to rickroll anyone. But what’s really annoying is that they make it impossible to send messages like this:
Oh, have you seen [paste copied URL]http://www.istocknow.com?
Try that, and the URL becomes a preview, and the question mark vanishes. It really interrupts conversational flow. You can prevent this by either writing text on both sides of the pasted URL, or surrounding the URL with angle brackets:
Oh, have you seen <[paste copied URL]http://www.istocknow.com>?
So there’s the quick tip: To prevent link previews, surround your pasted links with either text on both sides, or more simply, angle brackets.
But because I often forget to do that, I wanted it to be automatic. Thanks to Keyboard Maestro, I was able to make that happen: When I paste a link in Messages—using the system’s standard ⌘V shortcut—it’s enclosed in angle brackets. If I paste anything other than a URL, it’s pasted as is. If I do want a preview, I can use the actual Paste menu item instead to get a link with preview.
This solution is perfect for my needs, as I always use ⌘V to paste, and I so rarely want to send a link preview that it’s OK that it requires a trip to the menu. (If it ever does annoy me, I’ll just remap Paste in Messages to ⌃⌘V or somesuch.
I can use ⌘V to activate my macro (without doing anything to Messages’ Paste shortcut) because Keyboard Maestro (and other apps that trap keystrokes) trap them before the background app sees them. With my macro assigned to ⌘V, Keyboard Maestro activates the macro and Messages never sees the ⌘V keystrokes.
With that knowledge, the macro itself is very simple, with one little bit that threw me off for a while. Here’s how it looks, and as always, you can download for your own use.
As discussed, the trigger is set to ⌘V, so I don’t have to remember anything to make this work. The logic of the macro is all in the if conditional: I check to see if the current clipboard item starts with http. (The ^http construct is a regular expression, and the carat means “find from the beginning,” so it won’t match a sentence that contains a link, for example.)
If there is a match, Keyboard Maestro types the left angle bracket, pastes the clibpboard, then types the right angle bracket. If there isn’t a match, then the macro just pastes whatever’s on the clibpoard.
The one “gotcha” that threw me off for a bit was that I originally wrote this using Keyboard Maestro’s Paste action. In the final version, I paste by using the Select a Menu Item action to actually select Edit > Paste. Why is that?
It turns out that Keyboard Maestro’s Paste action works by sending ⌘V to the application. When it does that, it triggers the macro again, which sends another ⌘V, which triggers the macro again, which…well, you get the recursive picture. The end result wasn’t pretty.
Once I figured out that little workaround—good to know for other macros going forward, too—eveyrthing worked as expected. So if you dislike sending link previews, try this macro; I love how it “just works” and doesn’t require a new keyboard shortcut or changing my behavior in Messages.