Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Remove Safari history files on logout via shell script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Remove Safari history files on logout via shell script
Authored by: mat79 on Jul 01, '09 10:38:28AM
why use useroot=/Users/your_user
I really dont get this. whats wrong with using ~ instead?

#!/bin/bash

Clear Safari History (except for bookmarks).
rm -f ~/Library/Safari/Downloads.plist ~/Library/Safari/History.plist 
rm -f ~/Library/Safari/HistoryIndex.sk ~/Library/Safari/TopSites.plist 
rm -f ~/Library/Safari/WebpageIcons.db ~/Library/Safari/LastSession.plist

# Add any additional clean-up here.


[ Reply to This | # ]
Remove Safari history files on logout via shell script
Authored by: leamanc on Jul 01, '09 05:14:15PM

The problem with using ~ to denote your home folder is that it's just bad practice, in terms of portability. It won't work on all shell scripts in all environments. Sure, in this case, you're only going to be running it on OS X, and it will probably work all the time. But it's best to stick to the rules of scripting, and using the tilde, or other path shortcuts, is not recommended.

But, there is something you can use instead: the $HOME variable, as such:

rm -f $HOME/Library/Safari/Downloads.plist $HOME/Library/Safari/History.plist


[ Reply to This | # ]
Remove Safari history files on logout via shell script
Authored by: leamanc on Jul 01, '09 05:23:24PM

Looking into this further, the tilde might not even work, according to this archived OS X Hints forum post.

It says:

Commands don't understand tilde, only the shell.



[ Reply to This | # ]
Remove Safari history files on logout via shell script
Authored by: excarnate on Jul 02, '09 02:11:20PM

In this case it isn't commands, it is the shell. The shell expands the ~ so there is no problem.

~ really isn't that bad, I've never run into problems, but $HOME is slightly preferable, you can change the location of where it looks easily, say:
export HOME=/somewhere/else
say if you have an archived home directory you want it to work with. Maybe not something that applies here. Personally on little scripts that are special purpose I'd use ~ as it is easier and very clear.



[ Reply to This | # ]
Remove Safari history files on logout via shell script
Authored by: RedFred on Jul 06, '09 04:06:54PM

The Logout hook is run as root so ~ and $HOME refer to /private/var/root, not the home directory of the user logging out. See the hint below for the correct way to do this.



[ Reply to This | # ]