Change thumbnails in feeds to favicon

Currently, feeds apparently use the icon of the default browser as thumbnail for the posts and another generic icon for the feed itself. As an experiment, I wrote a small script that replaces the thumbnail for a feed and it’s post by the favicon of this site (see screenshot)
Bildschirmfoto 2020-06-01 um 22.12.28

For this experiment, I downloaded the favicon from within the browser as an .ico file and then converted it to a png with Preview. (Remark: apparently, DT3 cannot use the .ico file directly. That’s ok but I suggest that the documentation mentions the supported format for thumbnails).

Question 1: is it possible to download the favicon from a website programmatically? I tried using the method download URL but ended with a seemingly broken ico file.

Question 2: If I put this script in a smart rule, which trigger should I use so that the thumbnail is set whenever a feed is updated?

Feature request: Please use the site’s favicon as thumbnail for the feeds in a future release (at least optional). That would make identifiying feeds a lot easier (and more fun, in my opinion).

BTW: The “Data -> create thumbnail” function is not very helpful in this situation (again: my opinion). It does not use the favicon for the feed site, and the thumbnails for the posts are just very tiny renderings of the website.

Thanks in advance for all points

1 Like

How did the script look like and which URL did you use? This should actually work.

As there’s no such event the best option is probably On Creation.

Here it goes:

(() => {

  let app = Application("DEVONthink 3");
  app.includeStandardAdditions = true;
  let URL = "https://heise.de/favicon.ico";
  let iconRaw = app.downloadURL(URL);

  let currentApp = Application.currentApplication();
  currentApp.includeStandardAdditions = true;
  let desktopString = currentApp.pathTo("desktop").toString();
  let tmpfile = `${desktopString}/icon.ico`;
  let openedFile = currentApp.openForAccess(Path(tmpfile), { writePermission: true });
  currentApp.setEof(openedFile, { to: 0 })
  currentApp.write(iconRaw, { to: openedFile, startingAt: 0 })
  currentApp.closeAccess(openedFile)
 })()

The first part gets the favicon, the second part (following Application.currentApplication()) writes the data to a file. In case anybody is wondering about the usage of currentApp in this part, please cf. https://www.geofftaylor.me/2020/jxa-how-to-use-openforaccess/

The data retrieved with downloadURL starts like this:

'****'($00000100030030300000

(as reported in script editor)
However, if I look at the favicon as downloaded from within the browser, it starts with several ASCII zeroes. The same goes if I download it with curl.

I suppose that downloadURL converts the data to an ASCII representation since the file written bey the script is twice the size of the binary file downloaded with curl/the browser: 30182 vs. 15086

This simple AppleScript works fine over here on 10.15.5:

tell application id "DNtp"
	set theIcon to download URL "https://heise.de/favicon.ico"
	set thePath to "/Users/criss/Desktop/favicon.ico"
	set writeFile to open for access (thePath as POSIX file) with write permission
	set eof writeFile to 0
	write theIcon to writeFile
	close access writeFile
end tell

It does so here, too. However, there’s a difference in the data downloaded as shown by script editor:

tell application "DEVONthink 3"
	download URL "https://heise.de/favicon.ico"
		--> «data ****00000100030030300000

vs.

app = Application("DEVONthink 3")
	app.downloadURL("https://heise.de/favicon.ico")
		--> "'****'($00000100030030300000

Is this one of the weirdnesses in JXA or a glitch in DT3? I’m not averse to use AppleScript if it does the job. But if there’s a work around in JavaScript, I’d rather stick with it.

If I use

let iconRaw = app.doShellScript('curl ...')

all is good. Not overly elegant, but at least working.

For DEVONthink it doesn’t even matter whether it’s JavaScript or AppleScript, it always receives the same AppleEvents and returns the same data. But maybe it’s an issue of the JavaScript bridge of macOS.

Probably. This whole JXA thing was a good idea, but Apple apparently doesn’t follow up on it. There are so many weird things in it that should be fixed but aren’t :frowning:

Am I correct to assume that DT3 expects the thumbnail in a file, or could I also pass the binary data directly?

DEVONthink accepts binary data, paths and URLs. However, at least the last time I tried to use binary data I experienced weird AppleScript issues.

Thanks – in fact, I can just pass in the URL to the domain’s favicon.ico and DT3 does what I want. Interesting that it can load the ico data from the URL but not from the file.

Thanks a lot for your help!