Macos – How to set Safari to clear cache and cookies on startup

macmacososx lionsafari

Is there a way I can set Safari to clear cache and cookies on startup? Maybe a flag I could use when launching the application, or perhaps even a bash or applescript that would delete files on the hard drive and then launch the app?

Best Answer

Use the following AppleScript code and save it e.g. as an application in AppleScript Editor, or as a Service consisting of a single Run AppleScript action in Automator.

tell application "Safari" to activate
tell application "System Events"
    tell application process "Safari"
        tell menu bar 1 to tell menu bar item "Safari" to tell menu 1 to tell menu item "Reset Safari…" to click
        tell window "Reset Safari" to tell button "Reset" to click
    end tell
end tell

This will activate Safari, launching it if it's not running, and then open and submit the "Reset Safari…" menu item.

Related Question