Remove bogus entries from Safari's history file

Feb 04, '03 09:43:20AM

Contributed by: jmelloy

If you've enabled the Debug menu in Safari, you may have noticed the "Populate History" item. If you ... accidently ... click it, it fills your history with up to 1000 bogus sites. I've written a perl script that removes them.

#!/usr/bin/perl
use warnings;
use strict;
my $file="/Users/jmelloy/Library/Safari/History.plist";
$/="<array>";
open(FILE,$file) or die qq(Unable to open "$file": $!);
my $toss = <FILE>;
$/="</dict>";
my @history = <FILE>;
close(FILE);
my $outfile = "History.plist";
open(OUTFILE, ">$outfile") or die qq{Unable to open "$outfile": $!};
print OUTFILE $toss;
for(my $i = 0; $i < @history; $i++) {
if($history[$i] =~ /.*bogus.*/) {
}
else {
print OUTFILE $history[$i];
}
}
close(OUTFILE);
Copy that into a text editor, make it executable (chmod +x history.pl). All that needs to be changed is the username ("jmelloy"). It's non-destructive, it creates a new file in the same directory you ran the script from. Then, all you need to do is copy the new History.plist file to ~/Library/Safari/History.plist and you're done.

If you also want to remove "other" things from your history, all you need to change is the regular expression that matches the word "bogus".

Comments (3)


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