New GeekTool Script: Bloglines Notifier
In honor of me trying to get a job with Bloglines, I will show a new script that I whipped up this morning to take care of an itch of mine, a Bloglines notifier for GeekTool. At work, I have a notifier plugged into Firefox that works great for me, but on my Mac, I hate how Firefox acts and so I've never had a real notifier at home before. I know there are some out there, but I don't think installing yet another app just to track my RSS feeds is really going to make my life easier.
And so I came up with this:
First, you will need to install some perl modules. Don't freak if you don't know how to do this, it's really easy.
Open up Terminal.app or your favorite terminal program (iTerm, hint hint).
At the command line put:
sudo perl -MCPAN -e shell;
This will put you into a program that helps you install perl modules. It's called CPAN and it makes modules installation painless.
At the cpan prompt, type:
install WebService::Bloglines
There will be extra modules that you need to install too, but CPAN will handle all of this for you. When it asks you if it should install prerequisite packages, just hit enter (meaning yes) and it will take care of the rest. See! Easy!
Now that the modules are installed, let's look at a little script I put together:
#!/usr/bin/perl
use WebService::Bloglines;
# set up your login for Bloglines
my $bloglines = WebService::Bloglines->new(
username => 'user@name.com',
password => 'password',
);
print "Bloglines Notifier\n";
## get the number of unread items using Notifer API
my $unreadCount = $bloglines->notify();
if($unreadCount == 0){
print "There are no new items";
} else {
# If it's just one item, don't put an 's',
# otherwise tack it on
print "$unreadCount new post",
$unreadCount==1?'':'s',"\n\n";
}
This snippet will show a count of how many unread items you have, like most notifiers. But I wanted a little more. For me personally, not all blogs are equal and if certain blogs have new posts, I know I can wait a while, but if blogs I really like are updated, I want to read those posts now. Because of this, it would be helpful to know which blogs have been updated and not just how many unread I have total.
So I added a list of which blogs have been updated and how many unread posts they have. So at the bottom of the first script, I added this:
## Get site titles and unread count
# get all unread items
my @updates = $bloglines->getitems(0);
# go through each update and
# get the feed title and number of items unread
foreach my $update (@updates){
my $feed = $update->feed();
print "$feed->{title}";
# Since the API doesn't give us a count,
# we need to count the array of unread items
print ' (', scalar @{$update->items},")\n";
}
Et voila! A list of blogs with unread items, much like what you see on Bloglines.
Now you're going to want to copy this code into a file, called bloglines-geektool.pl or download it here, change the username and password to your Bloglines account and save it somewhere. Then in GeekTool, create a new Shell command and type perl /path/to/bloglines-geektool.pl. Set the refresh to 180 (3 minutes) or how often you want it to update and, under the Text tab, select Force Carriage Return (which means word wrap). Put it where you want it on your desktop and off you go.
This makes me wish there was a GeekTool equivalent for KDE, and I expect that there will be sometime. Being able to have this kind of information at my fingertips is really what computers are all about, right?