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.

2 Likes

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.

1 Like

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

On iOS, why does Drafts appear as an option under Share Extensions for some web pages but not others?

For example, when I click on share extension box at the bottom of Safari at this site, I see the Drafts app as one of the choices. But I do the same thing at this site and Drafts app is not available as an option.

Reboot your device. You are probably just seeing iOS 14 bugs with flaky extension registration, reboot should resolve.

Yep. That resolved it

1 Like
  • Browser Safari
  • Mac OS iMac
    Instead of needing to use the mouse.
    Is there a keyboard-command for the Safari share menu for Drafts to capture urls in this full format including the name of the URL?
    Example:
    image
  1. Open System Preferences.
  2. Select Keyboard.
  3. Select App Shortcuts.
  4. Select Shortcuts.
  5. Select “+” to create a new App specific keyboard shortcut.
  6. Set Safari as the app.
  7. Set the Menu Title as “File->Share->Drafts”.
  8. Set the keyboard shortcut to whatever shortcut you wish to use.
  9. Select Add.
  10. Close System Preferences.
    2021-04-27-21.17.53

In Safari, when you now press the keyboard shortcut it should trigger the share to Drafts as per the share template you have defined in Drafts.

Hope that helps.

@sylumer Thank you, this solution works perfectly.