Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'View Safari cache files while offline' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
View Safari cache files while offline
Authored by: oliverlangan on Sep 03, '09 03:01:19PM

Since this was posted, it seems that the cache file format has changed. It is now a SQLite database. The file can be found in the current user's folder:
~/Library/Caches/com.apple.Safari/Cache.db
You can browse the file with the sqlite3 command line tool, but it will be much easier to extract data if you use a GUI tool such as MesaSQLite.



[ Reply to This | # ]
View Safari cache files while offline
Authored by: tehthehteh on Nov 28, '11 04:31:34PM
Thanks for the tip! MesaSQLite looks great.

I put together this quick hacked shell script below, which gives you an overview of all images in the cache. It extracts the images from the cache, puts together a temporary HTML file on the desktop, opens the page in Safari and deletes it once loaded.
#!/bin/sh
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"" > ~/Desktop/cache.html
echo "    \"http://www.w3.org/TR/html4/strict.dtd\">" >> ~/Desktop/cache.html
echo "<html lang=\"en\">" >> ~/Desktop/cache.html
echo "  <head>" >> ~/Desktop/cache.html
echo "    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">" >> ~/Desktop/cache.html
echo "    <title>Cached Images</title>" >> ~/Desktop/cache.html
echo "  </head>" >> ~/Desktop/cache.html
echo "  <body>" >> ~/Desktop/cache.html
sqlite3 ~/Library/Caches/com.apple.Safari/Cache.db "SELECT request_key, time_stamp FROM cfurl_cache_response WHERE request_key LIKE '%.jpg' OR request_key LIKE '%.jpeg' OR request_key LIKE '%.gif' OR request_key LIKE '%.png' ORDER BY time_stamp DESC;" | perl -ne 'chomp; ($url, $time) = split(/\|/); print "<a href=\"$url\"><img src=\"$url\" alt=\"Downloaded at $time\"></a> <a href=\"$url\">$url</a> $time<br>\n";' >> ~/Desktop/cache.html
echo "  </body>" >> ~/Desktop/cache.html
echo "</html>" >> ~/Desktop/cache.html
open -a Safari ~/Desktop/cache.html
sleep 1
rm ~/Desktop/cache.html
Open up Terminal, type "nano cache", paste in this script, save using 'Ctrl-X' and then 'Y'. Run "chmod +x cache" to make it executable. Now, anytime you want to bring up all cached images, you can open up Terminal, type 'cache' and woo! Images! It also keeps the URLs, in case you want to search for a file name. A word of warning though: there might be a lot of images in there.

[ Reply to This | # ]