AppleScript to Insert Markdown Link for Current Safari Tab via TextExpander

Here’s a simple AppleScript which can be used with a TextExpander snippet, or as a Service via the macOS Automator app, that when invoked will insert the title and URL of the frontmost Safari tab, formatted as a Markdown link.

tell application "Safari"

    set theURL to URL of front document

    set theName to name of front document

end tell

get "[" & theName & "](" & theURL & ")"

I set up the TextExpander shortcut mdL for this. Be sure to set the snippet as an AppleScript snippet for this to work properly.

Now, when I find a link I want to save, I just switch over to nvALT as per usual, get the cursor where I want it, and invoke the snippet.

My old method was to use a Safari bookmarklet, which I had to click, then Copy, Esc the dialog, switch to t nvALT, Paste.

So much simpler now.

If you’d like to have some control over the link text before the Markdown link is inserted, head over to Dr. Drang’s  Markdown & TextExpander post which helped me formulate this snippet.

I set up Drang’s snippet as a companion, for those intermittent times when I want to modify the text prior to insertion.

Been wanting to add this to my setup for some time. Glad it was pretty straightforward.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s