I really like how I can use Drafts on the Mac to save a selection of a webpage with its URL into Drafts. It just gets tedious really quickly to go do this by hand and then switch to Drafts to add tags and such. Here’s a Keyboard Maestro script that provides the same information to Drafts when used in the share sheet and subsequently applies a Drafts action.
Note, for this to work you need to add a keyboard shortcut to the Drafts action of your choice and update the last KM action with that keyboard shortcut.
To use it: go to the webpage and select the text you want to capture. Press the hotkey trigger and watch a new Drafts note being created with the title and URL of the page as well as the selected text.
In my case the Drafts action adds a Drafts tag
In case it happens to be of use to anyone, here’s a fairly similar version that I’ve been using.
Overview:
It is set only to run when I’m in Safari.
It checks to see if anything is copyable to determine whether to just produce a Markdown link (page title and page URL), or if there is a text selection to be included as well.
It utilises a separate temporary clipboard to grab any text selection, leaving my system clipboard intact.
It builds the output in a Keyboard Maestro variable called toDrafts.
It doesn’t interact with Drafts via key presses, but rather runs an AppleScript to create a new draft (tagged with safari in this case), using the content of the toDrafts variable
It plays a small sound at the end so I get an audible cue it has completed.
Because I’m checking for the copy to clipboard functionality to be available, that drives whether I need to copy a selection or not. It is also using a separate clipboard, not the system clipboard that pbcopy uses in your suggestion. I want to retain the system clipboard and leave it untouched, this macro working independently of it.
So, I’m only copying a selection and utilising it if there is a selection made.
Sometimes it does only use that title and URL. That’s what it does when there is no selection. That’s on purpose.
There doesn’t need to be a system clipboard anywhere as I’m instructing Keyboard Maestro to use a named clipboard. That then leaves my original system clipboard intact.