I’ve just posted a script to the Drafts Action Directory. It is a simple script to take the URL copied from Safari, and create a Markdown link to it.
There are two ways you can use it:
- Press the button with no text selected.
You end up with something like[|](url_copied)
with the cursor between the square brackets (indicated with the character | in this example) - Press the button after selecting some text
You end up with something like
[this is the text I selected](url_copied)
In case you want to manually copy/paste the script into Drafts, here is the simple code:
// Create Markdown link
var sel = getSelectedText();
var selRange = getSelectedRange();
var clip = getClipboard();
if (!sel || sel.length == 0) {
setSelectedText("[](" + clip + ")");
setSelectedRange(selRange[0]+1,0);
}
else {
setSelectedText("["+sel+"]("+clip+")");
setSelectedRange(selRange[0]+selRange[1]+3,0);
}
This is by no means rocket science. I simply took the existing Markdown Link keyboard extension and added a variable that stores the clipboard content through the getClipboard() function.