(or Sign up) :

Don't Try This At Home

Mar 07

Show_hide

On the Mac there's a nifty little utility called Growl. It's a system-wide notification service that other applications use to display attractive popup status messages. There are all kinds of programs that utilize it, namely instant messaging apps and other small utilities. Sometimes they're really useful, other times they're fun and occasionally they're a little bit stupid.

I wrote a really stupid one. I mean a really, really stupid one. I added Growl notifications to dashing.com.

So now every time someone visits this site a little window pops up on my desktop announcing it. Is that the stupidest thing ever or what? :-)

Growl notifications

Now I confess that it is kind of cool. But the idea of the website sending notifications to my desktop Mac whenever people visit is really a terrible idea. But it was such a neat little hack I had to do it. :-)

So for you Rails programmers who are bored, here's how I did it.

First download Growl and install it if you don't already have it.

Next you'll need Ruby Growl. You can install that via RubyGems.

sudo gem install ruby-growl

Once that's installed add an after_filter to the top of your application.rb controller file.

after_filter :growl

Then add the following code to the bottom of application.rb.

Note: I'm using the Acts As Authenticated style user model code and helpers, so you may need to change this for your app, or remove the username display entirely.

 1   private

2 require 'ruby-growl'
3 def growl
4 if logged_in?
5 user = current_user.login
6 else
7 user = request.env['REMOTE_ADDR']
8 end
9 g = Growl.new 'home.server.address', 'Website Visitors',['visit'], ['visit'], 'PASSWORD'
10 g.notify 'visit', 'yoursite.com',"#{user} visited #{request.env['REQUEST_URI']}", 0, false
11 rescue
12 # Something didn't work
13 end

You'll want to replace "home.server.address" with the IP address or hostname of your Mac. Replace "PASSWORD" with your Growl network password and "yoursite.com" with the name of your website.

You'll need to enable incoming connections in the Network section of the Growl control panel, and be sure to set a password. Also check the "Allow remote application registration" button, at least until you've received your first message. Finally, if you have a firewall you'll also need to allow port 9887 access to your Mac over UDP.

That's all there is to it. It's really pretty fun to see all of the popups...at first anyway. Though I can't imagine this would work well with even a moderately popular website. In fact even dashing.com is too busy for this and I'll likely turn it off shortly. But it was a fun hack just the same.

Maybe this will inspire someone to come up with a useful reason to incorporate Growl into a Rails app? If you do, be sure to let me know.

6 responses to Don't Try This At Home

  1. Sandra 31 minutes later said:

    Can you see me now John?!

    (Being an only child, I always wanted a Big Brother...oh wait, you would be my little brother...oh well.)

  2. aCSfriend about 2 hours later said:

    Are you sure my boss didn't put you up to this?

    Sandra, I guess he's all of our Big Brother.

  3. eebee about 19 hours later said:

    Actually I think this is pretty cool, John.:) I think you should take it one step further and figure out how to make our user names appear in our former CS.com chat colors, LOL! I, of course, call fuchsia. :D

  4. FELINELUVR about 20 hours later said:

    Hey! Stop messing around with stuff like that. If you have time to figure all of that out, you have time to post more pics of The Babe! :-( IRIE ~Fe~

  5. L 9 days later said:

    GGGrrrrrrrrrrr......rrrrr

    Rruff! Ruff!

  6. sassafras-o about 1 month later said:

    John, that kinda reminds me of a 'talking' parrot my sister talked me into downloading. It was HUGE and flew onto my screen each time I had new email, IM messages, etc., plus at other times with a 'new' joke or cutesy comment.

    That dang bird nearly drove me crazy, but I was really lucky because my son bought me a new monitor when one night while I was trying to visit in a chat room, I threw my shoe at it.

    Sue

Post your comment below

Name:

Website:

Email:

Your comment: