Copy a URL and then paste it as a formatted link that always has the same word, eg, Link

I've gone through a bunch of posts here and as I'm merely a tinkerer and not a dev, much of it has gone over my head. I've spent about an hour now trying to do this and hope someone can help me. :pray: I use Chrome on Mac Sequoia.

I want to press a keyboard shortcut like CTRL + Q and have it copy the URL of the current browser tab and then paste it as a formatted link, always using the word "link". Like this: Link

I found How do I construct a link (title with embedded link) in KM, then paste that into evernote or an email? and Set Clipboard to RTF Hyperlink & Plain Text MD Link

... but to be honest, I feel like they're more complex than I need or else I'm not understanding what they say. The first one I need to install or use Python, which I don't know the first thing about.

I tried using the Set Clipboard to RTF Hyperlink & Plain Text MD Link and it worked briefly, but when I tried to set a keyboard shortcut for it, it stopped pasting the word and instead posted the formatted URL like this: https://forum.keyboardmaestro.com/t/set-clipboard-to-rtf-hyperlink-plain-text-md-link/1608/8.

Now, I can't get it to work at all. I tried the debugger but it doesn't show anything that seems helpful. I have deleted the macro and redownloaded it several times. It doesn't change anything. It's still not working.

It's clear it's not grabbing the URL because these should be filled in.

image

Thanks for any help!

If I'm understanding this properly, you want to always create a Markdown-style link with the link text being a word ("Link"), and have that on the clipboard? If that's right, this simple one-action macro should do what you want:

Link front browser tab Macro (v11.0.3)

Link front browser tab.kmmacros (1.3 KB)

This uses the %FrontBrowserURL% token, which does what its name suggests, and formats it in Markdown style directly to the clipboard. Change "Link" to whatever you want.

If this isn't what you want, there are other more-powerful link creation tools here, including one I wrote:

-rob.

1 Like

yep! i just want an HTML link from all of this. I'll check out what you've shared here. Thanks!

Wait, HTML or Markdown? If you want HTML format instead, just edit the action:

<a href="%FrontBrowserURL%">Link</a>

-rob.

That gives me this - the actual code for the URL in HTML. Discourse formats it but the platform I'm in does not support Markdown, so this code doesn't help.

<a href="https://forum.keyboardmaestro.com/t/copy-a-url-and-then-paste-it-as-a-formatted-link-that-always-has-the-same-word-eg-link/38231/2">Link</a>

What I want is this, where it's already formatted.

Link

For ex, if I pasted it into Slack it would just show up as code, not Link.

What are you pasting it into? It sounds like you need an actual hyperlink, which is different than the code to create a link?

-rob.

yes! I need a hyperlink.

The problem with this, at least as I understand it, is that it requires knowing what the destination app expects a link to be. Some apps (Discord) will format a link when the text is input in the right form. Other apps (Word) require you to click on a selection of text and go through the process of inserting the link.

So in whatever app you're using, how do you create a link in that app? That's the behavior you'll have to replicate with Keyboard Maestro. There's no such thing as a "universal hyperlink," at least to my knowledge—hopefully someone will correct me if I'm wrong.

-rob.

1 Like

Hi, @lady3jane. If you upload your macro, I can help you out later today.

Thanks to some JXA code that I have borrowed from @ComplexPoint, I have a few macros that populate the clipboard with links. When the links are pasted into a text editor, they take the form of markdown, i.e., [title](url), whereas when pasted into an rich text editor (e.g., TextEdit, Word, Mail), the links are pasted as hyperlinks.


This reference material might also help:

1 Like

It's a custom web app for where I work. Just assume it's like Slack. It's not something that allows you to use markdown.

You highlight the text and paste the URL and it turns into a prettified link.

I don't have a macro, I've just been trying the ones linked above.
Thanks though for any help!

So you would highlight the word "Link", and then hit Command-V to create a link in this web app?

-rob.

yes that's right

Then that should be even simpler: Take the macro I posted earlier, and just change it to this:

%FrontBrowserURL%

Then add a second action, Paste. Assign a keyboard shortcut, and if you have text highlighted in your app, when you hit the shortcut, the frontmost browser's URL should be inserted as a formatted link.

Please note that this depends on your app behaving exactly as you described: With a URL on the clipboard, and text selected in the app, pressing Command-V (or Edit > Paste) results in a clickable link with the selected text. If that's true, then the above should work perfectly for you.

It can get fancier if you want to be in your browser when you run it, but for now, it's set up to simply grab whatever the frontmost browser window is while you're in your app.

-rob.

2 Likes

Please take a look at this and let me know if you have any questions...

Download: Create Two Flavor Links in the Clipboard.kmmacros (23 KB)

Macro-Image


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 15.1 (24B83)
  • Keyboard Maestro v11.0.3

1 Like

oh gosh! this is amazing! Thank you. It works perfectly! :raised_hands:

1 Like

@lady3jane, that's great; glad to help!


When I see someone new to the forum, I like to share a few helpful entries: