Saving RFCs to DEVONthink via AppleScript

Since I work from RFCs a lot, I decided it would be a good idea to start downloading them locally to make them easier to refer to, search, annotate, and so on. I’ve put together a quick AppleScript so that if I’m browsing my RFCs group and don’t find the one I’m looking for, I can choose Download > RFC from the script menu, enter the number, and it does the necessary. Thought I’d post the script here for anyone else who deals with RFCs or other reference documents.

set response to display dialog "RFC number?" default answer "" with icon note buttons {"Cancel", "Download"} default button "Download"

set rfcNum to text returned of response as Unicode text

if rfcNum is not "" then
	set theURL to "https://www.rfc-editor.org/rfc/rfc" & the text of rfcNum & ".html"
	tell application "DEVONthink"
		create formatted note from theURL in current group
	end tell
end if

Improvements welcome of course!

3 Likes

Something seems to have broken this script. It has started downloading the RFCs as Web Archives, rather than Formatted Notes. Seems like a bug?

  • You haven’t provided any information about the version of DEVONthink or macOS you’re running.
  • It’s impossible to directly test this without a valid URL.
  • Testing with another URL produced a formatted note, as expected in DEVONthink 4.3 on macOS Tahoe 26.5.1.

DEVONthink 4.3, just updated to 4.3.1 and the problem’s still there.

macOS 26.5.1.

Example URLs would be RFCs 6874, 3968, 3986, and 4007.

Web preferences:

I don’t know anything about the site, but it’s built in a peculiar way and I don’t know if that’s new or not. That being said, using the script with other sites is producing a formatted note.

The HTML is not valid (missing doctype, missing title attribute in head element. The document contains neither images nor CSS nor fonts. Which makes a webarchive pointless (IMO).

Here’s a JavaScript variant of the code that will always save a formatted note:

(() => {
  const app = Application("DEVONthink");
  app.includeStandardAdditions = true;
  const response = app.displayDialog("RFC number", 
    {defaultAnswer: "", 
    withIcon: "note", 
    buttons: ["Cancel", "Download"], 
    defaultButton: "Download"});
  const rfcNum = response.textReturned;
  const rfcURL = `https://www.rfc-editor.org/rfc/rfc${rfcNum}.html`
  const doc = app.downloadMarkupFrom(rfcURL);
  const f = app.createRecordWith({"record type":"formatted note", 
    name:`RFC${rfcNum}`, URL: rfcURL,source: doc}, {in: app.currentGroup);
})()

Tried it with two of your sample RFCs and it worked fine. Translating to AppleScript should be trivial

2 Likes
set rfcNum to text returned of (display dialog "RFC number?" default answer "" with icon note buttons {"Cancel", "Download"} default button "Download")

if (rfcNum is not "") and (rfcNum's length = 4) then -- I don't know if the length is fixed but it's a good example of multiple conditions on a line
	tell application id "DNtp"
		set theSource to download markup from "https://www.rfc-editor.org/rfc/rfc" & rfcNum & ".html"
		if theSource is "404 - Not found" then return
		create record with {record type:formatted note, source:theSource} in current group -- The name is added automatically. DEVONthink is smart like that ;) 
	end tell
end if
1 Like

Thanks! Newer RFCs are proper HTML, older ones are text wrapped up to be an HTML page.

I think I prefer a JavaScript solution in case I need to make it do any additional processing. I still find AppleScript endlessly frustrating.

As you wish, though in all my years automating things, AppleScript is much easier for the average layperson to read and understand. If JavaScript scratches your itch, go for it.

PS: I hope this illustrates to readers how easy it is to jump to a wrong conclusion.