TextExpander Snippet: Extract the Real URL from a Google Search Results Link
The Problem
You’re searching Google, looking for a link to email/blog/otherwise save. In this example, you’re looking for me, but you’re confused as to how my name is spelled.
Great, let’s grab that first link:
Paste that into your text editor, and you see… oh.
You can, of course, actually visit the link in question, then copy the URL from your address bar. Or you could edit the URL, turning %2F
into /
as you go. I’ve done both, thousands of times. So have you. Neither is particularly entertaining.
The Solution
I searched in vain for a TextExpander snippet to take care of this, but I didn’t turn one up. (OK, I didn’t search that hard; writing one is more fun)
Now, after copying the link, I type
;ungoogle
into my editor, and all the tracking cruft is removed, leaving me with:
Getting the Snippet
You’ll need to download and install the Ungoogle TextExpander Snippet, it will be preassigned an ;ungoogle
shortcut. Feel free to change the shortcut as you see fit.
One prerequisite: the snippet is actually a Perl script, and you’ll need the URI::Query module installed. sudo cpan URI::Query
will do the trick from the Terminal.
You can also just create a new “Shell Script” snippet of your own, and paste in the Perl:
#!/usr/bin/perl
use strict;
use warnings;
use URI;
use URI::Query;
my $googleUrl = `pbpaste`;
my $uri = URI->new($googleUrl);
if (($uri->authority =~ /google\.com/) && ($uri->path =~ /^\/url\b/) && ($uri->query =~ /\burl=/))
{
my $q = URI::Query->new($uri->query);
my %params = $q->hash();
my $url = $params{'url'};
print "$url\n";
}
else
{
print $googleUrl;
}