Script to set feed thumbnails to favicon

The URL is

The script has changed slightly:

function performSmartRule(records) {

  var app = Application("DEVONthink 3");
  app.includeStandardAdditions = true;
    
  var feedURL, URLmatch, httpPath, favIcon, favTry;
  records.forEach(f => {
	  feedURL = f.url();
	  app.logMessage("1: " + feedURL);
	  URLmatch = feedURL.match(/(https?|feed)(:\/\/[^/]+\/)/);
	  app.logMessage("match: " + URLmatch.length);
	  if (URLmatch[1] === "feed") {
	     httpPath = "http" + URLmatch[2];
	  } else { 
	     httpPath = URLmatch[1] + URLmatch[2];
      }
	  favIcon = httpPath + "favicon.ico";
	  
	  favTry = getIcon(app, httpPath);
	  if (!favTry) {
	    favTry = getIcon(app, httpPath.replace(/(feeds?|rss)\./,""));
	  }
	
	  app.logMessage("3: " + favIcon);
  	  favIcon = favTry ? favTry : favIcon;
	  f.thumbnail = favIcon;
	  app.logMessage("4: f.type - " + f.type());
	  if (f.type() === "feed") {
  	    f. children().forEach(c => {
	      c.thumbnail = favIcon;
		})
	  }
    })
  }

  function getIcon(app, url) {
 	 app.logMessage("getIcon " + url);
     let favIcon = null;
     const HTML = app.downloadMarkupFrom(url );
	 const embImages = app.getEmbeddedImagesOf(HTML, { baseURL: url});
	  favIcon = embImages.find(img => 
	    (img.match(/\.ico$/) || img.match(/\/favicon/) || img.match(/icon/,"g")));
      app.logMessage("found: " + favIcon);
      return favIcon;
  }


  var app = Application("DEVONthink 3");
  app.includeStandardAdditions = true 
/*  let dbName = "Feedly"; // NOTE: Adjust this to your database name 
  let db = app.databases.whose({name: dbName})[0].root();
  let feeds = app.search("kind:feed", {in: db});*/
  performSmartRule(app.selection()); 

The script can’t detect the right URL in this case and uses https://travel-dealz.de/favicon.ico but the correct URL is https://travel-dealz.de/app/uploads/sites/2/cropped-Travel-Dealz-Icon-32x32.png

I don’t really mind that the Favicon is not found in this case.

It bothers me that the script throws an error when run inside of DT3 on the selection and runs through if I run it outside of DT3, i.e. in the script editor.

Der Feed funktioniert übrigens wahrscheinlich auch nicht, d.h. die korrekte URL ist ALL - Accor Live Limitless: Gold-Status mit (mindestens) einer Accor-Aktie » Travel-Dealz.de

thx @cgrunenberg, i tried on many URLs. Its all bookmarks i added via the DT clipper so they are .webloc files such as this

best

Z

Apply Rules uses only those items of the selection matching the conditions of the smart rule. You could drag & drop the items onto the smart rule instead, in this case the rule is applied to alle dropped items.

Anyway, the next release will include a new get favicon of AppleScript command plus a revision of the above smart rule script.

1 Like

ok @cgrunenberg, cool ill wait to the next version :slight_smile:

the drag and drop solution didn’t work for me bit im totally find with waiting :slight_smile:

thx again

Z

Cool. One suggestion for the script: instead of retrieving the icon for a post from the website, I suggest to simply copy it from the corresponding feed. That should be a lot faster and less resource consuming.
Provided, of course, that the feed’s icon has been set correctly when the feed was created.

This procedure doesn’t work in JavaScript, by the way, because thumbnail() returns a completely useless ASCII string. I wish, Apple would fix its automation infrastructure…

It’s a generic script for all kinds of items having a URL and personally I wouldn’t even like this :slight_smile: but scripts can of course be easily customized.

Ok, aber das Problem (nämlich: Fehler -1708, nachdem das Skript durchgelaufen ist und danach jedesmal, bevor das Skript läuft) tritt auch hier auf
https://www.docma.info/software/nik-collection-3-mit-non-destruktiver-bildbearbeitung-und-neuem-perspective-tool
und da findet das Script ein Favicon.
Ich vermute, es ist wiedermal eine Unzulänglichkeit in JXA.