SEARCH

How-To Geek

Create Your Own “Insert Hyperlink” Feature in Any App with AutoHotkey

If you’ve ever used Microsoft Word or Windows Live Writer, you’re probably familiar with how you can highlight some text and then use the Ctrl+K keyboard shortcut to convert that text into a hyperlink. If you’re in a text editor, it’s not quite that easy… until now.

What we’ve done is put together an AutoHotkey script that automates the process of creating a link, and we’ll demonstrate it using the WordPress post editor, though that’s not the only place you could use this technique.

Using Our New “Insert Hyperlink” Feature

First we’ll assume that you’ve already copied the URL to the clipboard, and then you will simply select some text that you want to turn into a link—assuming you are in the HTML view, of course, since you wouldn’t want to do this in the visual editor.

image

Now you’ll press the shortcut key that you’ve chosen—for our example, we’re using Alt+9 since that’s rarely taken by anything else…

image

And just like that, the text is replaced with the hyperlink including the URL you had on the clipboard.

Note: Of course, in the WordPress editor, you could always use the Alt+Shift+A shortcut key instead, which would launch a dialog allowing you to enter the link, but we’re just using this as an example—though you might note that our method requires only a single keystroke.

image

Creating the “Insert Hyperlink” Feature

To create the feature for yourself, either create a new AutoHotkey script, add the following to your existing script, or download the file at the bottom and run it. Naturally we’re assuming you already have AutoHotkey installed.

!9::
{
  Sleep, 100
  clipurl := clipboard
  Send ^c
  Sleep, 50
  clipurl := "<a href=""" . clipurl . """>" . clipboard . "</a>"
  SendInput {Raw}%clipurl%
  clipboard := clipurl
  clipurl =;
  Return
}

Here’s how it works… you’ll notice that we’re using Alt+9 as our keyboard shortcut, but you can customize this to anything else you’d like.

The first line inside the brackets pauses the script for 1/10th of a second to make sure that you’ve released the shortcut key, then the clipurl := clipboard line copies the current clipboard (the URL) into a variable to save for later. Once that’s done, the script automates copying the selection to the clipboard with Ctrl+C, assembles the link together, and then pastes the whole thing back into the application, replacing the current text in the process. The last step puts the clipboard back to the way it was before you ran the command.

Download the “Insert Hyperlink” AutoHotkey Script

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 07/30/10

Comments (4)

  1. David Levine

    I actually didn’t know about the Ctrl+K keyboard shortcut, so I learned two things.

  2. Aaron

    This is fabulous!

    I think I’ll add a check to verify there’s a well-formed URL on the clipboard first, then fail silently if not. I don’t think that’ll be too tricky in AHK.

  3. Toban

    This script doesn’t return the clipboard to its original state. The variable ‘clipurl’ gets changed from just the url to the whole html tag, so when the clipboard is restored with ‘clipurl’ it contains the whole html tag.

    I solved this by creating a new variable so that ‘clipurl’ doesn’t change. The two changed lines look like this, with ‘html’ being the new variable to hold the html tag:
    html := "" . clipboard . ""
    SendInput {Raw}%html%

  4. SFdude

    Hi Toban, (and How2Geek!),

    @ Toban:
    tried the AHK script changes in your comment,
    but then, the script stops working completely…

    Can you be more specific,
    ie: show the whole new AHK script?
    (I suspect there are more than the 2 changes you suggest…).

    Anyone?

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!