Clearing Safari's History Automatically at Logoff - PCWiki
 |  RSS
Subscribe to magazine
Personal tools

PC World Documents

Views

Clearing Safari's History Automatically at Logoff

From PCWiki
Jump to: navigation, search

If you're annoyed at Safari's persistent persistence, remembering everything you did, wherever you went, etc., then here's a solution. The script I provide here will nuke all of Safari's histories whenever you log off.


Sure, Safari has 'Private Browsing', but it doesn't remember to KEEP IT PRIVATE. As soon as you quit Safari and start it again, it starts recording what you did again.

So I spent a little time tracking down a few things and made a BASH script to take care of it, then found a hook to get it called at logout. The script can be further modified to use a 'shred' tool instead of 'rm', if you're really paranoid, and you can add whatever other 'clean up' you like to it. You can also invoke the script 'on demand'.

It should be noted that this only clears your local history. Logs on servers and whatever other records may still exist to remember what you did and what sites you visited. This will only keep your web browsing private from typical snoops, not 'The Man'.

Anyway, everything works 'normally' and it remembers what you've done for your whole session until you log out, at which point it cleans everything up.

1. Copy/paste the lines at the bottom of this document beginning with '#!/bin/bash' into a new text file and save it as 'privacy.sh'. 2. Edit the script, replacing 'youraccount' with your own account name. 3. Make the file 'executable'. In the shell, that's 'chmod +x privacy.sh' 4. Quit (Command-Q) Safari and test the script. Re-launch Safari. It should have forgotten everything but your bookmarks. 5. When you're satisfied with the behavior, invoke this command, substituting 'privacy.sh' with the path to where you put YOUR privacy.sh... sudo defaults write com.apple.loginwindow LogoutHook "privacy.sh" ... It will prompt for a password to give permission to add the hook. 6. Browse to a few sites to make a 'history'. 7. Log out/in or restart the computer. 8. See if the files in the Library/Safari and Library/Cookies went away. 9. Go into Safari and see if the history is empty. It should contain just your 'Home Page', if you have one. 10. You're done.

To be complete, go to Safari->Preferences->AutoFill, and clear all of the checkmarks (it won't remember passwords and forms). You shouldn't let the browser 'remember' passwords for you, since anyone who gets access to your computer will have access to all of your accounts, and since most people promptly forget ALL of their passwords as soon as their computer is entrusted with them, when something happens to the computer they end up locked out of everything.

The script cleans up everything but your 'Bookmarks.plist' file, which contains your bookmarks. Future versions of Safari (or older versions than 4.0) may have 'different' files. So you'll definitely want to review the contents of the script and the contents of the folders the script deals with and modify the script to make sure you 'get' everything, and revisit the script whenever you end up with a new version of Safari.

{code}

  1. !/bin/bash
  1. Copy/paste this command and point it at wherever you put this script
  2. sudo defaults write com.apple.loginwindow LogoutHook "/Users/youraccount/scripts/privacy.sh"
  3. Script runs as root when invoked at logout, so you may want to make sure this has protected privileges.
  4. Make this point at your own user folder

useroot=/Users/youraccount

  1. Clear Safari History (except for bookmarks).

rm -f $useroot/Library/Safari/Downloads.plist $useroot/Library/Safari/History.plist rm -f $useroot/Library/Safari/HistoryIndex.sk $useroot/Library/Safari/TopSites.plist rm -f $useroot/Library/Safari/WebpageIcons.db $useroot/Library/Safari/LastSession.plist rm -f $useroot/Library/Cookies/*

  1. Add any additional clean-up here.

{code}

Name City
Address 1 State Zip
Address 2 E-mail (optional)