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
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:
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
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.