Skip to content

Instantly share code, notes, and snippets.

@Next-Door-Tech
Forked from dardo82/safari-favicons.sh
Created January 31, 2018 05:36
Show Gist options
  • Save Next-Door-Tech/a94bf2b1a666506d0d806229300dc4a0 to your computer and use it in GitHub Desktop.
Save Next-Door-Tech/a94bf2b1a666506d0d806229300dc4a0 to your computer and use it in GitHub Desktop.
Fix Safari FavIcons
#!/bin/zsh
# Fix Safari Favorites Icons
LSD="Library/Safari"
TIC="Touch Icons Cache"
TAB="cache_settings"
DIR="/$HOME/$LSD/$TIC/"
DBF="$DIR/${${TIC// /}%s*}${${(C)TAB}/_/}.db"
SQL=$(sqlite3 "$DBF" "SELECT host FROM $TAB")
diff <(ls "$DIR/Images") <(for i in "${=SQL}"; do echo ${(U)$(md5 -qs $i)}.png; done | sort)
sqlite3 "$DBF" "UPDATE $TAB SET ${${${(L)TIC// /_}#*_*}/s/_is_in}=1,download_status_flags=1"
for file in "$1"/*.png; do
URL="$(plutil -convert xml1 -o - "$HOME/$LSD/Bookmarks.plist" | \
awk -F '[</>]' -v f="${${file##*/}%%.*}" '{if($3~f){for(i=0;i<3;i++)getline;print $5}}')"; \
cp -fv "$file" "$HOME/$LSD/Touch Icons Cache/Images/${(U)$(md5 -q -s $URL)}.png"
done
exit
@dardo82
Copy link

dardo82 commented Jun 30, 2018

@Cancun101 take a look at the new revision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment