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 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:
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)