For posts you would have to use “On News”, for feeds after creating them “On Creation”.
Hi all
for some reason i cant get it to work for me. I tried both @chrillek js
script and @cgrunenberg applescript
methods with no success
this is what i have so far
i then stand on a DT bookmark and try to execute the rule
but nothing happens. Can any one guide me towards what im screwing up
thx!
Z
Very nice - thank you
Not a big deal but… is there an easy way to adjust the favicons for dark mode?
What’s the URL of the bookmark?
No.
I’m running into weird problems with the JS version of the script: It runs ok once if I use “Apply rule” from the context menu, but terminates with an error -1708 (as can be seen in DT3’s protocol window). After that, it throws the same error without even doing anything (I peppered the code with logMessage calls).
If I run the exact same script in the script editor with the current selection (i.e. the same html file as in DT3), it works ok and doesn’t throw an error. Supposedly, this is some kink in JXA, but maybe I’m doing something stupid here?
A screenshot of the complete log might be useful.
DEVONthink 3 caches scripts to speed up their execution.
That’s the log:
11:29:34: 1: https://travel-dealz.de/deal/le-club-gold-status/?utm_source=feed&utm_medium=rss&utm_campaign=rss-feed
11:29:34: match: 3
11:29:34: getIcon https://travel-dealz.de/
11:29:34: found: undefined
11:29:34: getIcon https://travel-dealz.de/
11:29:34: found: undefined
11:29:34: 3: https://travel-dealz.de/favicon.ico
11:29:34: 4: f.type - html
11:29:34: ~/Library/Application Scripts/com.devon-technologies.think3/Smart Rules/Favicon.scpt on performSmartRule (Fehler -1708)
11:30:49: 1: https://travel-dealz.de/deal/le-club-gold-status/?utm_source=feed&utm_medium=rss&utm_campaign=rss-feed
11:30:49: match: 3
11:30:49: getIcon https://travel-dealz.de/
11:30:49: found: undefined
11:30:49: getIcon https://travel-dealz.de/
11:30:49: found: undefined
11:30:49: 3: https://travel-dealz.de/favicon.ico
11:30:49: 4: f.type - html
The first part, up to and including the error message, comes from the rule being run in DT3
The rest is from the rule being run directly in script editor on the current selection.
I’m aware of the fact that DT3 is caching external scripts. What actually happens, is this:
- I start DT3
- I select a record and run the rule on it
- all the messages are logged to the protocol window, including the final error message
- I run the rule again on the same selected record
- no messages are logged to the protocol window except for the final error message
So it seems that the script is somewhat “tarnished” after being run for the first time.
Since I don’t want to spam the forum, I don’t post the script here right now. Please let me know if I should do that or send it via personal message (or not at all
What’s the URL of the itme? Is the script above the latest version?
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.
ok @cgrunenberg, cool ill wait to the next version
the drag and drop solution didn’t work for me bit im totally find with waiting
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 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.