Possible to bypass prompt for Clip with preset values? or any alternative x-devonthink:// url scheme?

I’ve been looking for an automatic web archiving solution, and it just occurred to me that the answer might be staring me in the face, in the form of the Clip to DevonThink browser extension.

I took a look at its code and setting it to activate whenever a page loads, instead of when it is clicked, was trivially easy, and it indeed does call the x-devonthink://clip? URL as desired.

But this brings up the clipper prompt, and I obviously don’t want to click that whenever I import. I just want it to automatically save it in a preset directory (or just inbox and I’ll take care of it with a smart rule).

Is that possible using the x-devonthink://clip URL scheme, or otherwise is there another solution I’m not thinking of?

I realize I could simply send the URL to DevonThink using a x-devonthink://createwebdocument scheme, but without handing over cookies that wouldn’t work for non-public sites.

Turns out the x-devonthink://createwebdocument approach works great when you pass in source:

(function() {
    if (navigator.appVersion.indexOf("Mac") >= 0) {
        var url =
            'x-devonthink://createWebarchive?title=' + encodeURIComponent(document.title) +
            '&location=' + encodeURIComponent(window.location) +
            '&referrer=' + encodeURIComponent(document.referrer) +
            '&width=' + window.innerWidth +
            '&encoding=' + document.characterSet;

        var isChrome = (navigator.appVersion.indexOf("Chrome") >= 0);
        var source = encodeURIComponent(document.documentElement.outerHTML);
        if (!isChrome || (url.length + source.length) < 2097152) {
            url += '&source=' + source;
        }

        window.location.href = url; // Changed from 'window.document.location' for clarity
    } else {
        console.log("The Clip to DEVONthink extension only works on a Mac.");
    }
})();

var activate = function()
{
	chrome.tabs.executeScript(null, {file:"activate.js"});
}

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if (changeInfo.status === 'complete' && tab.active) {
        chrome.tabs.executeScript(tabId, {file: "activate.js"});
    }
});

// The rest of your existing main.js code...


// Existing activate function and other code...


chrome.browserAction.onClicked.addListener(function (tab)
{
	activate();
});

chrome.commands.onCommand.addListener(function(command)
{
	if (command == 'activate')
	{
		activate();
	}
});

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse)
{
	if (request.action == "devonthink_activate")
	{
		activate();
	}
});

```manifest.json
{
  "background": {
    "scripts": ["main.js"]
  },
  "content_security_policy": "script-src 'self'; object-src 'self'",
  "description": "Modified script.",
  "permissions": [
    "tabs",
    "<all_urls>"
  ],
...}

The only issue is that it brings up Devonthink each time. I’m guessing that’s just in the nature of such URL schemes. If anyone has any clever ideas for how I can automate creating and saving webarchive files into Devonthink whenever i load a page, I’d appreciate it.

Thanks for sharing this! Actually it is x-devonthink://createWebArchive like in the above JavaScript code. By the way, bookmarklets for various formats are available on our website:

The only issue is that it brings up Devonthink each time. I’m guessing that’s just in the nature of such URL schemes.

Yes, of course that’s the inherent and expected behavior for a URL scheme.

If anyone has any clever ideas for how I can automate creating and saving webarchive files into Devonthink whenever i load a page, I’d appreciate it.

That sounds potentially undesirable. Please clarify your use case.

Use case is wishing my browser history were full-text searchable, so I can more easily find sites, articles, etc. that I only vaguely remember months or years later.

I switched my approach to have the extension submit the HTML to a simple FastAPI endpoint on a home server, which places the files in a Syncthing folder that’s indexed in Devonthink. After a couple days it became clear this would quickly balloon into a massive and unwieldy database, so now I have the FastAPI server apply Readability and convert to markdown before syncing/indexing to Devonthink.

Separately I also have ArchiveBox running and saving offline copies in various formats of the sites I visit. Unfortunately the automatic archiving feature of its browser extension only works in Chromium-based browsers (I much prefer Safari or Orion), and the way it’s designed it doesn’t take the actual page source from the browser, instead it retraces the browsers steps, resulting in double the bandwidth consumption and no archiving of personalized / logged-in content.

Use case is wishing my browser history were full-text searchable, so I can more easily find sites, articles, etc. that I only vaguely remember months or years later.

Interesting… why not clip as you go? Speaking for myself, my browser history would have more chaff than wheat :wink: so I clip as I work.

1 Like

You could try HistoryHound.app

HistoryHound lets you do a fast keyword search on the entire content of all web pages and RSS feeds you’ve visited recently, plus all those that you’ve bookmarked. It’s a “personal web search.” Just type in a few keywords and HistoryHound gives you a list of pages you’ve viewed recently, ranked by relevance.

If you sync your iPhone’s and Mac’s Safari via iCloud then HistoryHound will also include what you’ve visited on the iPhone.

And it’s possible to search with (some) of the Google search operators, e.g. site:https://discourse.devontechnologies.com returns everything for the given time range.

3 Likes

That’s really cool. I’ve used other apps from the same developer but was not aware of HistoryHound. Thanks!

1 Like