With URL in clipboard, compose Postbox email with URL title in subject line, URL in body

Macro here: SEND URL IN CLIPBOARD 1.0

This macro uses the technique from a macro I posted about earlier which lets you copy a hyperlink and output a Markdown link, i.e., [URL Title](URL).

In this instance, the macro takes a URL in the clipboard and opens an email compose dialog in Postbox, taking advantage of Postbox's scriptability.

My goal here was to avoid the inconvenience of having to open the URL in a new browser tab or window in order to get the "send current URL" functionality.

Here it is in action:


Here is what the macro looks like, in relevant part.

Cheers!

1 Like

Here is a method that is much simpler to create a Markdown link from a selected hyperlink, which should be much, much faster than having to retrieve the entire web page HTML source:

It uses this script, provided by @ComplexPoint in this post:

(function (oNode) {

  var oLink = document.evaluate(
    "./ancestor-or-self::a",
    oNode,
    null, 0, 0
  ).iterateNext();

  return oLink ? 
    "[" + oLink.text + "](" + oLink.href + ")" :
    "";

})(window.getSelection().anchorNode);
1 Like

Hey @BKammer,

What browser are you using?

-Chris

Hey Jim,

This doesn’t work in Safari 11.1 on macOS 10.12.6.

(Chrome does work.)

-Chris

Well, that sucks. :wink:

There is another method I've used that should work across browsers. When I get a moment I'll test it.

Chris and @BKammer:

Try this:

updated 2017-11-12 23:30 CT

This should be better, more robust, but still has had on limited testing.
I hope you guys can give it more exhaustive testing. Thanks.

'use strict';
(function run() {      // this will auto-run when script is executed
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PURPOSE:  Get Markdown Link of Selected Hyperlink
VER:      1.0    2017-11-12
AUTHOR:    @JMichaelTX
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

var scriptResults = "TBD"

var rngSel = window.getSelection().getRangeAt(0);

var ancElem = rngSel.startContainer.parentElement;

if (ancElem.tagName === "A") {
  var urlSel   = ancElem.href;
  var textSel = ancElem.text;
  var mdLink   = "[" + textSel + "](" + urlSel + ")";
} else { var mdLink = ""; }

 scriptResults = mdLink;

return scriptResults;
}  // END of function run()
)();

Works for me in macOS 10.11.6 with:
Google Chrome 61.0.3163.100 (3163.100)
Safari 11.0.1 (11604.3.5.1.1)

But it has had ONLY very LIMITED testing.

2 Likes

Safari.

(Anyone have insight into why my Droplr image links are not working anymore?)

(UPDATE: They seem to be working now!)