Copy favicon?

I have a trivial need. To decorate a palette of web sites I would like to copy each site’s favicon to the corresponding macro icon. Does anyone know a way to copy a site’s favicon? I have found some in /Users/mlm/Library/Safari/Touch Icons but nowhere near as many as I would expect, and since they are not named a visual search is necessary.

Oddly, I found all sorts of pixel dimensions in those icons, not the 16x16 or 32x32 I expected. (I found one that was 160x160.) I don’t understand how that works, unless something has radically changed about favicons since I last paid attention to them quite a while ago.

Thanks Mitchell for pointing out this folder.

Apparently the plist file CacheSettings.plist, in this folder, identify each favicon by its date:


Hope this help,

Curious: what application do you use to read property lists. Xcode unfortunately gives the date in the form “Jun 5, 2016, 4:57:49 PM”. I’ve read plenty of plists, including with Emacs, but this one is in Apple’s binary format so I can’t use Emacs. BBEdit works

There are only 176 entries in that dictionary, and I’ve probably visited 10X that many web sites. Wonder where some kind of limit would be stored. Or maybe it’s the most recent sites visited, which would work out OK for what I want.

There still remains the weirdness of the varying sizes of icons.

Good idea for a macro or, more likely, an AppleScript action that looks up a domain, extracts its date, then selects the file in Touch Icons the icon whose date (added, created, modified appear to all be the same for each file) corresponds to the TouchIconLastRequestDate key for the domain. I don’t have time right now to write that, but maybe someone else will find it interesting enough to work on.

I am still confused about how this works. Just went to a new web page, but its favicon is not in the folder (looking ordered by date, but also looked at icons).

Have you tried using Safari's Develop->Show Web Inspector? I went to, then opened the inspector, and I found this in the web page's "head" section:

I clicked the link (shown in blue in the above image), and it downloaded this .ico file:

Then I used the icon in a Google Image search, and of course found matches of all varying sizes.

Quite a sledgehammer! I’ll have to try it for the ones I really care about.

“Touch Icons” are from the iOS world.

Turns out the real icons are in — no surprise — Webpageicons.db. I tried using SQLite Browser on the .db file, and was actually able to find icons by double-clicking on the BLOBs in the IconData table. A bit tricky to find the icon for a page URL, though. Fun!

I know you didn’t mean anything bad by this comment, but I actually think the things you are doing are the sledgehammer methods! :grinning::stuck_out_tongue:

After all, I’m suggesting you get the icon using the same URL the browser uses, just like it was meant to. You’re the one with the hammer and crowbar digging around in the internals!

(I hope it’s obvious I’m just joking around here. If not, well, I’m just joking around here!!)

I was looking for a small brush :slight_smile:

What I meant by sledgehammer, and yes I was joking, was going into the HTML through the web inspector. I am neither uncomfortable, nor adverse, to doing that. I just get obsessive about finding and manipulating information. i was just using the SQLite Browser to see what was going on – didn’t mean I’d use it to find icons. (Although that would make an interesting small programming project.)

Having seen how the icons are stored I think I have to conceded that yours is the only same method without doing some programming, all for a very minor thing I will do only very occasionally/

I totally get that. I’ve been trying to find where Notification Center stores its information for a while now, to solve an issue of duplicate entries for an AppleScript scriplet I wrote a while back. It used to be in a SQLite database in some place like ~/Library/Application Support/NotificationCenter/*.db. In fact, that file still exists, but it’s no longer used.

Still, it was fun spelunking with a SQLite browser.

I used TextWrangler the sibling of BBEdit.

Hey Mitchell,

Not exactly a small brush, but a configurable one.

This script sends the Safari page source to BBEdit.

You can use similar techniques to search for favicons in the code.

# Auth: Christopher Stone
# dCre: 2010/11/13 21:15
# dMod: 2015/12/05 10:43
# Appl: Safari & BBEdit
# Task: Open source of front Safari window in a new BBEdit window.
# Libs: None
# Osax: None 
# Tags: @Applescript, @Get, @Safari, @Source, @Generated
--» MAIN

   tell application "Safari"
      tell front document
         set {_name, _src} to {name, do JavaScript "document.body.parentNode.outerHTML"}
      end tell
   end tell
   tell application "BBEdit"
      make new text document with properties ¬
         {contents:_src, source language:"HTML", name:"genSrc: " & _name, bounds:my desktopBounds(), soft wrap text:false}
      tell front text window to select insertion point before character 1
   end tell
on error e number n
   stdErr(e, n, true, true) of me
end try

--» deskTopBounds()
--  Task: Get bounds of Finder's Desktop Window
--  dMod: 2011/09/25 01:01
on desktopBounds()
   tell application "Finder"
      set _bounds to bounds of window of desktop
      set item 2 of _bounds to 44
      return _bounds
   end tell
end desktopBounds
--» stdErr()
--  Task: General error handler
--  dMod: 2013/05/31 04:22
on stdErr(e, n, beepFlag, ddFlg)
   set e to e & return & return & "Num: " & n
   if beepFlag = true then
   end if
   if ddFlg = true then
      tell me
         set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
      end tell
      if button returned of dDlg = "Copy" then set the clipboard to e
      return e
   end if
end stdErr

This script requires the Satimage.osax AppleScript Extension. to be installed. It will return a list of any found favicon URLs.

# Auth: Christopher Stone
# dCre: 2016/06/08 05:43
# dMod: 2016/06/08 05:43 
# Appl: Safari
# Task: Find favicon URL(s) in the source of Safari's front page.
# Libs: None
# Osax: Satimage.osax { }
# Tags: @Applescript, @Script, @Safari, @Find, @Favicon @URL

tell application "Safari"
   tell front document to set pageSource to do JavaScript "document.body.parentNode.outerHTML"
end tell
set faviconList to fnd("href *= *(?>(?!href).)+favicon[^'\"]+", pageSource, true, true) of me

if faviconList ≠ {} then
   # Do something
end if

on fnd(_find, _data, _all, strRslt)
      find text _find in _data all occurrences _all string result strRslt with regexp without case sensitive
   on error
      return false
   end try
end fnd


Since BBEdit runs 24/7 on my system I’d probably output any found items to it.


1 Like

I just discovered something basic, very convenient, and surprising: If no favicon is designated in the head element, browsers will look for favicon.ico in the site’s root directory.