Push notification hack

There’s an app in the iPhone app store called Prowl which is like a Growl client for the iPhone. For those of you who don’t know, Growl is a program for Mac OSX (and Windows too, apparently) that pops up notifications on your screen about various things of interest. Most Mac apps that wish to notify you of something probably use Growl. For example, your IM program can pop up a notification when your buddies sign on, or you can get a notification when you receive new emails. Prowl is an iPhone app (and a Growl plugin) that uses the iPhone push service to push your computer’s Growls to your iPhone. Well, that sounds pretty cool, right? But why do I care? I don’t have a Mac, or even a Windows computer. Well, it turns out that the guy behind Prowl is pretty cool, and has made a public API available for use by anyone! Of course, I set to work hacking something similar to a Growl push service for Ubuntu. Ubuntu (and Gnome in general) doesn’t have Growl, but it has something very similar. Libnotify is a library that pops up unobtrusive notifications on a Gnome desktop in the same way that Growl does on Mac. Other programs can cause libnotify to display a notification by making a request over the d-bus. D-bus is a nifty inter-process communication framework for Linux. Someone cleverly wrote a Python wrapper around the Prowl API, and of course there are d-bus bindings for Python too. So it’s just a matter of detecting the “notify” message on the bus, and then pushing the bubble’s data to your iPhone using the Prowl API! It should be noted that for this to work, bus eavesdropping has to be enabled in /etc/dbus-1/session.conf (on Ubuntu). Also, I’m using mail-notification on Ubuntu. This is a little app that sits in your panel and notifies you when you get a new email. Anyway, I couldn’t find examples of how to do this anywhere, so I ended up reading the source for dbus-monitor to see how it does it. Then I hacked together this little script:

#!/usr/bin/python
import sys
import dbus
import gobject
import prowlpy
import lxml.html
from dbus.mainloop.glib import DBusGMainLoop

apikey = 'PROWL_API_KEY'
p = prowlpy.Prowl(apikey)

def handler(*args):
	a = args[1].get_args_list()
	if len(a) > 0:
		if a[0] == 'Mail Notification':
			n_data = a[4]
			n_data = lxml.html.fromstring(n_data)
			n_list = n_data.text_content().split('\n')
			print 'New email! Pushing it to phone...',
			try:
				p.add(n_list[0].split(':')[1], n_list[1].split(':')[1], n_list[2].split(':')[1])
				print 'Success!'
			except Exception, msg:
				print msg

DBusGMainLoop(set_as_default=True)

bus = dbus.SessionBus()
bus.add_match_string_non_blocking('type=method_call')
bus.add_message_filter(handler)

loop = gobject.MainLoop()
loop.run()
Saturday, January 2, 2010

Dropbox and automatic scripts

A few days ago I upgraded to Ubuntu 9.10. While at work, I needed to SSH to my home computer, but I had forgotten to install SSH server. I happened to be renewing my love for Dropbox at the time and I decided to write a program that would monitor a Dropbox directory on my computer for scripts, and execute them. That way I can run arbitrary commands remotely, even if I forgot to install SSH. There are obvious security problems with this, so I’ve tried to skirt around them by requiring that each script be cryptographically signed by me. Ultimately, I wrote the code as a shell script instead of a Python script or other program, because it was a lot faster and easier. You can download the script here. Make sure to change your GPG key ID on line 62. If you spot any bugs or errors, please let me know! To use this script, just run it with the full path to the directory to be watched. Scripts have to be tar’d along with their signature into a file called scriptname.dbox. Optionally, you can also include a file called “hostname” which should contain the hostname of the machine that you want to execute the script on (in case you are running this on multiple computers, but only want the script to execute on one of them). Here’s an example, assuming you want to execute the script myscript.sh on the computer grindelwald.

$ gpg --detatch-sign myscript.sh
$ echo grindelwald > hostname
$ tar cf myscript.dbox myscript.sh myscript.sh.sig hostname
$ mv myscript.dbox ~/Dropbox/Scripts
Sunday, November 1, 2009

360

I think I’m going pack up my XBox 360, or take it to work. We used to have one there, but someone took it back home. Without it, we’ve resorted to juggling during our break times. Lame, or awesome? If I don’t pack it up or move it, it’s just going to tempt me. I’ve tried limiting myself to only playing on the weekends, but not after 11:00pm. That worked fine, but I feel like I shouldn’t even play at all on the weekends. Not for a while. So I’m thinking of taking it to work until I’m done with GREs or applications or something. Just 2-3 months or so, really. I’m pretty possessive of my stuff though. I take care of my things to a neurotic degree. For example, I clean my laptop regularly. Not everyone at work shares this behavior. So I’m kind of worried about taking my XBox there. I know all it will do is sit around on a table and occasionally be turned on, but I’m still a little concerned. Oh well, I’m sure it’ll be fine.

Tuesday, August 18, 2009

Hello world!

Ah I finally did something about making a blog. I have been wanting to for a while. The problem was that I never realistically expected myself to post to a blog consistently. When I went to India this summer, I wanted to record my experiences somehow. I thought that I should start small with a Twitter account (here). After all, Twitter is just a micro-blogging service. Well, that didn’t really go as planned. I posted semi-regularly at first, and then not so much. And I’ve hardly posted on it since getting back. I guess I don’t see the novelty any more. In any case, I figured I’d just jump in and start blogging now that a friendly character told me that I can use his hosting service with my dusty old domain name which was just lying around unused. Here I hope to record the little projects that I do, and my thoughts about larger projects. I’ll probably also post about other things in my life as they come to me.

Sunday, August 16, 2009