
I'm pretty much in love with Alfred;
it's usually the first thing I install on a Mac. For whatever reason,
though, I rarely use it to fire off Google searches, usually going
straight to my browser. But today I fired off a search from Alfred
and was aghast to see a crappy hijacked results page from my ISP,
who I'd previously praised for having a fairly mature attitude toward
all things internet and not requiring me to have TV service with them.
I think I invented at least three new, wildly-offensive swear words
when I realized what was happening.
Now, my ISP hides a tiny little opt-out link in an area of the page that,
is virtually invisible due to its proximity to what my brain perceives as
pure garbage. (In fact I'd written most of this before I even noticed it
was there at all!) But you might not be so lucky, or, depending on the
way the opt-out is implemented, you might not stay opted-out, and anyway,
isn't a clever DIY solution more fun?
Since Alfred just makes a URL and hands off to the OS's preferred browser,
I fired up Charles to see what was going on.
Sure enough, they're intercepting GETs to
http://www.google.com/search?q=whatever and throwing back a 302 to their
own, crappy search, and I was able to quickly duplicate the behavior in
my browser by cooking up the same form of URLs.
But why hadn't I noticed this before, using the search box in Safari,
or by going straight to Google first? The reason is that my ISP's
pattern-matching is delightfully naïve, so it doesn't catch the richer
URLs that Google or Safari construct. This gives us the key we need to
craft a workaround for Alfred: a custom search!
Custom searches are the cat's pajamas--I've rigged up a bunch for work
to quickly drop me into our wiki, issue tracker, and so forth. Rather
than waiting for the Alfred developers to provide a fix for the search
hijacking, we can make our own custom search quickly and easily.
First, start by disabling the default Google search in Alfred. Open up its
preferences, navigate into "Features", then "Web Searches", and then uncheck
the Google checkbox:

Next, select "Custom Searches" and click the "+" to create a new one.
You can then monkey with the URL to slip past The Man--for example, a simple
alteration to the query string like http://www.google.com/search?&q={query}
can do it. In my case, I chose to make the simple switch from HTTP to HTTPS,
as it's likely to be more robust and gives me a nice, encrypted channel.

To get the same nice logo that Alfred's default has, we can go get the icon out
of the app itself. Right-click (or control-click) Alfred.app in your
Applications folder and select "Show Package Contents". Then open the
"Contents" and "Resources" folders and you'll find all of the icons. Find the
"google.png" image and drag it over into the icon drop zone in your custom
search.
Finally, we need to wire our new search into Alfred's "Fallback Searches".
Pop open the one that's currently set to "Search Google for '...'" and scroll
down to the bottom, where you'll find the custom search below a separator:

And that's all there is! Alfred is restored to full Google-searching glory.
I'd like to say a huge thank you to the developers of Alfred for providing the
flexibility that made this not only doable but easy. Huzzah!
