TextExpander snippet: Clipboard text link using Safari top tab (Applescript)

I rely on my TextExpander snippet to pop in the top Safari tab as a Markdown link an awful lot. The way it’s set up, it uses the title of the site it’s on as the text of the link. I usually end up changing it.

I’ve noticed, however, that often I type the text first and only realize I want to make it a link a little later. At that point it’s a little annoying to cut that text, type the snippet, then select the link text and replace it with the text I already typed. I eventually got around to adding another snippet to make this easier.

tell application "Safari"
    set theURL to URL of current tab of window 1
    set theTitle to "%clipboard"
    set mLink to "[" & theTitle & "](" & theURL & ")"
    return mLink
end tell

All you have to do is select the text you want to link, cut it to the clipboard, then invoke the snippet.

You can subscribe to this and other useful TextExpander snippets I use here.