How to get icons in Safari favorites (aka favicons) to display correctly

bookmarksiconsafari

I am using Safari on macOS Sierra. I have added several commonly-used sites to my favorites section, like so:

My favorites icons

(there are 10 icons, and all but 2 of them are displayed as the proper, correct icon from the site. For example, the Wikipedia icon has the large W icon. However, for Google Drive and Gmail, the icons are just big, ugly, generic G's)

I would like for the two Google sites to correctly display their icons as well. At first, I thought it was because all 8 of the "correctly displayed" sites had successfully configured their "Safari settings" or something like that, while Google failed to do this (although this doesn't sound too plausible).

However, if I instead go to the top menu in Safari, click Bookmarks > Show Bookmarks, I get the following:

My bookmarks list

Strangely, this time, the two Google sites do have correctly displayed icons, while it is instead three other sites (out of the 10) that aren't displayed: namely Wikipedia, Amazon, and New York Times.

So it seems that there are two sets of icons, "big" and "small", and for big icons, Google Drive and Gmail are not displayed correctly, while the other 8 are, and on the other hand, for small icons, Google Drive and Gmail are displayed correctly, while Wikipedia, Amazon, and NYTimes are not.

I actually don't care too much about the small icons, but I would really like for all the big icons to display correctly. How can I do that?

Best Answer

#!/bin/zsh
# Fix Safari Favorites Icons

CS="cache_settings"; TIC="Touch Icons Cache"; DIR="$HOME/Library/Safari/$TIC/Images"
DB="$DIR/../${${TIC// }%%s*}${${(C)CS}//_}.db"; SQL=$(sqlite3 "$DB" "SELECT host FROM $CS")
sqlite3 "$DB" "UPDATE $CS SET ${${${(L)TIC// /_}#*_}//s/_is_in}=1, download_status_flags=1"
for png in "$1"/*.png; do URL="$(plutil -convert xml1 -o - "$DIR/../../Bookmarks.plist" | \
awk -F '[</>]' -v name="${${png##*/}%%.*}" '$3~name{getline;getline;getline;print $5}')"; \
cp -f -v "$png" "$DIR/${(U)$(md5 -q -s $URL)}.png"; done; chflags -v uappnd $DIR $DB

From here: https://gist.github.com/dardo82/f7cc7c5c864fb5afa04bb12ecbcf3a9f

The script takes a folder with the missing touch icons as its only argument.

Each favicon needs to have the same name as the bookmark associated with it.

The newly updated gist works with Safari 13 but now if you clear the browser cache the added favicons disappear in the new tab and reappear upon restart!

Related Question