AppleScript: Copy page URL as markdown formatted link 20:17 on Wednesday

It’s been slow on the blogging side of things, but not on the working side. Besides doing Real Work, I’ve also entertained myself with writing a few simple AppleScripts. I’m not completely sure which is the greater good here, unwinding and killing time while scripting or “enhancing my productivity” with the scripts…

Anyway, I thought to share, sharing being the ethos of the social web and all.

I use Markdown for my blog posts (and FYI, it works in comments too) and hence I set forth to cook a script which copies the url of a page along with any selected text (usually the title of the article) to the clipboard. From there it can be easily pasted to a blog post.

Requirements: a Mac, Safari, appreciation of Markdown, preferably the Script Menu enabled.

Copy the code from below or download the script.

tell application "Safari"
  set linkTitle to do JavaScript "getSelection()" in document 1
  set linkUrl to URL of document 1

  set markdownText to "[]: " & ¬
    linkUrl & " "" & ¬
    linkTitle & """

  set the clipboard to markdownText
end tell

Comments are closed.