If you want to clean your Safari cookies, but you want to keep certain (login) cookies, you could manually remove cookies from the Safari preferences menu -- Safari » Preferences » Security » Show Cookies. However, that can be time consuming. As an alternative, try this Perl script:
#!/usr/bin/perl
use strict;
use warnings;
use File::Slurp;
### Edit this to your liking (put a pipe character between two words)
my $keepCookiesWith = "aap|teun|betterbe|tweakers.net";
### Put your OS X short username here (there should be a directory with the same name under /Users)
my $userName = "teun";
### ### ### Don't edit beneath this line unless you know some Perl
my $path = "/Users/$userName/Library/Cookies/Cookies.plist";
my @date = localtime();
my $date = sprintf("%04d%02d%02d", $date[5] + 1900, $date[4] + 1, $date[3]);
my $cookies = read_file($path);
rename ($path, $path . "." . $date);
open(WH, ">$path");
print WH <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
EOF
while ($cookies =~ m#(\s*<dict>.+?</dict>)#gs)
{
my $cookie = $1;
if ($cookie =~ /$keepCookiesWith/)
{
print WH $cookie;
}
}
print WH <<EOF;
</array>
</plist>
EOF
close (WH);Mac OS X Hints
http://hints.macworld.com/article.php?story=20090207074358144