Capture quotes from webpages with refering URLs

Hi all

And sorry if this has been asked several times before, but I couldn’t find an answer to it.

I’m looking for a way to capture (text) highlights from articles I’m reading online - either with a keyboard shortcut or an Alfred workflow.

The action should capture whatever text I have highlighted, create a new draft with the next and also include the URL of the webpage where the text is captured from.

How do I make that?

1 Like

Drafts has a share extension on the Mac which can do this in Safari, just as it can on iOS. Click the share menu in the Safari toolbar, then Drafts. You may have to select “More…” and enable the Drafts share extension.

Catalina (10.15) note: As of the time I am writing this response, macOS 10.15.3 still has a bug that prevents third party share extensions which integrate with Safari from being enabled. They simply do not appear in the list of share extensions in System Preferences. This has been reported to Apple by multiple sources, hopefully they will resolve soon.

1 Like

That is exactly what I was looking for. Thanks.

But - there is always a but - is there a way to get it to work in other browsers (Chrome) both on macOS and iOS?

No. It relies on special integration options available to extensions only through Safari that allows access to the current page via JavaScript.

Thank you so much for this. You have saved me a lot of trouble. I was beginning to think it was a problem with my setup that the Drafts share extension was nowhere to be found.

I don’t use Alfred, so I can’t tell you how to use it to run an AppleScript, but this is (approximately, at least) the AppleScript you can run:

tell application "Google Chrome"
  set theURL to URL of front window's active tab
  set theQuote to (execute front window's active tab javascript "window.getSelection().toString()")
end tell
get theQuote & linefeed & linefeed & theURL

This gives a plain text result, with the quote followed by a blank line and the URL. You can jazz it up with Markdown or HTML as you see fit.

As you can see from the last line, the output is left just sitting there. I don’t know how to make a new draft directly, as there appears to be no AppleScript dictionary for Drafts.

If I needed this ability, I would use Keyboard Maestro to run the script and paste the results wherever the cursor is (presumably in some text editor). Chrome doesn’t have to be the active app for it to work.

20200217-191543

I don’t think it’s possible to do the equivalent on i[Pad]OS, as Chrome doesn’t have a Shortcuts extension for running JavaScript.

1 Like

I would add that it should be possible to create a javascript bookmarklet to copy the page title, URL and highlighted text in Chrome or Firefox to the clipboard. I’ve cobbled together similar bookmarklets in the past, but my javascript isn’t good enough to do it quickly. From there, it might be possible to have KM or Alfred “open” that bookmark in your browser, and then put the clipboard contents into Drafts.

On Reddit I found the following JavaScript snippet

javascript:window.location='drafts://x-callback-url/create?text='+encodeURIComponent(document.title+'\n')+encodeURIComponent(location.href)+'&action=URL%20to%20Scratch&x-success=googlechrome://';

But I can’t get it to work properly… (my JS skills are very basic)

Well, I feel foolish for not thinking of using a URL scheme. This will work:

To @tf2 and @marsnielson’s points, I’m sure the same idea would work in a bookmarklet, but I’m not skilled enough at them to try.

One thing about this macro is that Chrome asks for permission to open Drafts every time I’ve run it. I suspect there’s a way to turn that warning off, but

  1. I almost never use Chrome, so it’s not worth it to me.
  2. The extra safety is probably worth the slight annoyance of having to give approval each time.
2 Likes

That is great… got it to work as a Alfred workflow.
In Chrome you can give permission to run Apple Scripts so it doesn’t show the warning

Thank you so much for you help!

2 Likes

Is there a way to change the format that it saves in? Right now it seems to be:

[page_title](page_url)

> selected_text

But I’d like something more like:

> selected_text

- page_url

Then I’m surprised you don’t want Something like

[linktext - url](url)

as that would be the best of both worlds.

Sure, that’d be OK too. I’m curious if that is possible