Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Here is a Python script that clears cookies from Safari (OS X):

from Foundation import *
store = NSHTTPCookieStorage.sharedHTTPCookieStorage()
L = store.cookies()
print len(L)
for c in L:
    store.deleteCookie_(c)
print len(store.cookies())

Is there a similar API to clear Safari's Cache and LocalStorage?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

For the cache, you would be looking at NSURLCache and the method(s) removeAllCachedResponses and removeCachedResponseForRequest

For the LocalStorage, there does not appear to be an API for talking directly to Safari LocalStorage except through JS.

I did find this AppleScript however which basically circumvents the API and deletes the SQLite databases directly, obviously replace USERNAME with your username.

tell application "Finder"

select every item of folder "LocalStorage" of folder "Safari" of folder "Library" of folder "USERNAME" of folder "Users" of startup disk
move selection to the trash
end tell

Finally, there's a project on SourceForge called SafariCleaner which does all that you are trying to do in a set of AppleScripts.

share|improve this answer
    
Thanks for the answer. I explored this more at length here: telliott99.blogspot.com/2012/04/…. –  telliott99 Apr 7 '12 at 12:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.