Kenneth Falck's Blog

Safari: AdBlock and keyword search with Privoxy

Posted on 2009-09-11 by Kenneth Falck

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 : 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(.*)/$@$1@} }

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 /.