After switching from Firefox to Safari 4 on Snow Leopard, the two features I miss the most are ad blocking and keyword searches. Luckily both can be added with Privoxy, which acts as a local HTTP proxy and filters Safari's requests.

The easiest way to install Privoxy is with MacPorts. Once it's running, Safari needs to be configured to use Web Proxy Server 127.0.0.1 : 8118. Most ads should then be blocked automatically.

Keyword searches can be added as redirect actions to Privoxy's configuration file at /opt/local/etc/privoxy/user.action. Just these two lines at the end:

{ +redirect{s@http://w%20(.*)/$@http://en.wikipedia.org/w/index.php?search=$1@} }
w%20*/

Now when you type "w hello world" in the Safari URL box, it will be redirected to Wikipedia search. More redirections can be added with the same logic, just replace both occurrences of "w" with the keyword. Note that Privoxy sees both the keyword and the argument as the DNS hostname (spaces become %20), and the path component of the URL is always /.

Published 11.9.2009