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?
Macos – How to set Safari to clear cache and cookies on startup
macmacososx lionsafari
Related Solutions
In recent versions of Safari (I am on 5.1 now), local storage can be cleared with Safari » Reset Safari » Remove all website data. Or by using Safari » Preferences » tabsheet Privacy » Cookies and other website data » Remove All Website Data. And even by using Remove All when viewing the details on that very same Privacy tabsheet. The Security tabsheet no longer shows any button to view the databases.
Some more details, also for older versions:
On my Mac, I found the folder ~/Library/Safari/LocalStorage
, which has a file for each site that uses local storage†, with its creation date set to my very first visit to each site. On Windows, this might be in a folder like %APPDATA%\Apple\Safari
or %APPDATA%\Apple Computer\Safari
.
Deleting all those files, and restarting Safari, obviously cleared the data for StackAuth too.
However, logging in to a random Stack Exchange site gets me the StackAuth data again, and a file in the above folder, without ever being prompted to allow that (my Safari preferences show "Database storage: none allowed before asking"), and without the domain being shown in the "Show databases" list. This also happens in private browsing modes.
This seems to be caused by the difference between HTML5 Web Databases, and HTML5 Web Storage (the latter including local storage). Chrome shows both for Twitter:
Apparently Safari only warns for databases, not for local storage? Maybe blocking local storage is going to be as hard as stopping Adobe Flash from leaving its privacy trail. The specifications state:
User agents should expire data from the local storage areas only for security reasons or when requested to do so by the user.
Let's hope someone knows of an easier way, or that we get some more control in future releases. (I filed a feature request at Apple for that.)
† In my case, I found as many as 5,904 items dating back to March 2009. And even my own domains, for which I'm sure no local storage is used, were listed with 8kb files each. Investigation shows that Alexey Ruzanov's FlashBlock user script uses local storage too, and hence causes a file for each site one visits, regardless whether it uses local storage, and regardless whether it uses Flash.
This is normal and doesn't represent a problem. People tend to think of RAM as being either occupied or free, but that isn't actually the case. A file cache is a perfect example of this.
When you copied that data from the external drive, it had to read the contents into RAM first so it could then write it to the other drive. Copying 5 gigs of data into RAM is a computationally expensive operation. Now what if you wanted to use those files you just copied? The computer is betting that you will, so it kept the copy in RAM around so that it doesn't have pay that cost again if you do.
Now here's the kicker that addresses the heart of your question: Does having 5.66 gigs of data in the file cache really only leave you with 250-400 MB of RAM available? Nope. That 5.66 GB is still free as far as the operating system is concerned. Why? Because the computer can dump that RAM in a nanosecond if it were needed for something else. It is more beneficial for you to have your RAM filled with cached copies of stuff than it is to have it sitting empty doing nothing. The smarter the operating system is about what to cache, the faster your computer is.
Even though that program is telling you the truth about how much RAM is being used, at the same time it is misrepresenting the amount of RAM you have available.
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.
This will activate Safari, launching it if it's not running, and then open and submit the "Reset Safari…" menu item.