Is there any way of convincing Safari to clear the cache when it quits? If not from Safari's options, then maybe an extension that does this?

I would use private browsing instead, but unfortunately it doesn't seem to work well for me (some sites say they can't use cookies, and a lot of functionality is broken with this enabled).


The menubar app Cookie can clear exactly what you want to clear at quit, at timed intervals, or both.

Can also clear thosenefarious Tracking Cookies, as well as non-favorite cookies, Flash and other databases -- and do this for all your browsers.

Not part of the company--just think especially with Tracking, it's a must have. SweetPea Productions, trial available.


You could assign a shortcut to a script like this:

osascript -e 'quit app "Safari"'
rm -rf ~/Library/Caches/com.apple.Safari
rm -rf ~/Library/Caches/Metadata/Safari/History
rm -rf ~/Library/Safari/Databases
rm -f ~/Library/Safari/Form\ Values
rm -f ~/Library/Safari/Downloads.plist
rm -f ~/Library/Safari/History.plist
rm -f ~/Library/Safari/HistoryIndex.plist
rm -f ~/Library/Safari/LastSession.plist
rm -rf ~/Library/Safari/LocalStorage
rm -rf ~/Library/Safari/TopSites.plist
rm -rf ~/Library/Safari/WebpageIcons.db
rm -rf ~/Library/Saved\ Application\ State/com.apple.Safari.savedState

It doesn't remove:

  • Preferences stored in ~/Library/Preferences/com.apple.Safari.plist
  • Bookmarks
  • Information stored in keychains
  • Extensions or their settings
  • Notification warnings (~/Library/Safari/UserNotificationPermissions.plist)
  • Location warnings (~/Library/Safari/LocationPermissions.plist)

I used dtrace to check which files were opened or deleted when I used the Reset Safari dialog.

sudo opensnoop -n Safari
sudo dtrace -n 'syscall::unlink:entry{printf("%u %s %s",pid,execname,copyinstr(arg0));}'

You can enable the Develop menu to clear the cache if you don't want to clear your history.

From your Safari menu bar click Safari > Preferences, then select the Advanced tab, then Show Develop menu in menu bar.

Now, from the menu bar click Develop > Empty Caches or use the keyboard shortcut, Option+Command+E.


This seems to be a working free option:

Safari Cleaner (applescript): http://macscripter.net/viewtopic.php?id=38244

Download from sourceforge: http://sourceforge.net/projects/safaricleaner/


I think it's not a good idea to scribble in system files directly. Let's do this job by Safari by automated action:

# clear cache and history of safari
# LB 10'2016 Ver 05

set SafariQuit to false # say to Safari good bye if we want

tell application "Safari" to activate # a good way to start safari without cookies
tell application "System Events" to tell process "Safari"
    set frontmost to true

    click (menu item "Verlauf löschen …" of menu 1 of menu bar item "Verlauf" of menu bar 1)

    if exists sheet 1 of front window then # check, if safari is runnung without of window
        click button "Verlauf löschen" of sheet 1 of front window
        click button "Verlauf löschen" of front window
        set SafariQuit to true # safari is running without window and also not used actually
    end if
end tell

if SafariQuit then
    tell application "Safari"
    end tell
end if

# accessibility Inspector.app (Xcode)
# http://www.leancrew.com/all-this/2012/04/accessibility-inspector/

Make'n App from this, add a nice "Safari in Waste".icns, put it in the dock and have fun. Don't forget to give this new App the rights to act in

  • This script works now for Safari Version 10.0 (11602. – Lima Oct 11 '16 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .