An AppleScript to sanitize Safari

Nov 11, '05 05:56:00AM

Contributed by: Anonymous

I recently moved from Firefox to Safari after upgrading to Tiger. One thing I missed was the ability to 'sanitize' (clear history, cache, cookies, saved searches etc.) my browser. Although Safari has a Private Browsing, feature I prefer the following method, which lets me keep my cache, history, and cookies until I want them gone, instead of not creating them in the first place.

I'm new to both the UNIX shell and AppleScript, but managed to create this simple AppleScript which executes a shell script. As you can see, it deletes the current user's Safari cache folder, cookies file, history and download history file. It also deletes the recent Google searches from Safari's preferences file.

try
do shell script "rm -r ~/Library/Caches/Safari
  ~/Library/Cookies/Cookies.plist ~/Library/Safari/Downloads.plist 
  ~/Library/Safari/History.plist ; 
  defaults delete com.apple.safari RecentSearchStrings"
end try 
Note: The do shell script line has been broken into four lines here for narrower display. Make it one line only, with a space replacing each line break.

One thing I couldn't manage to implement was something that would delete any saved form searches (like the one at MacUpdate). Safari seems to save these to com.apple.Safari.plist as keys beginning with com.apple.WebKit.searchField, followed by different names for each form.

I've only used this with Safari 2, but assume everything is stored in the same place with Safari 1, so it should work with that too.

[robg adds: You could also use the Reset Safari menu item, but you'd also lose your saved usernames and passwords if you do so...]

Comments (18)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20051107093733174