Accessing Growl via OS X Dashboard widgets

Published on 29/03/2009

Recently, while working on the latest version of Airmailr, a user suggested the introduction of Growl integration. Initially I thought this would be impossible, given that OS X’s dashboard widgets run primarily via JavaScript. After having dug around in Apple’s Dashboard Programming Topics, however, I came across an article entitled Creating a widget plug-in, which documents the creation of an Objective-C Cocoa bundle and the ability to link it to your Dashcode projects.

Being something of an XCode newbie, I continued my Google search for possible alternatives, which is when I came across Andrew Hedges article: Sending Growl notifications from Dashboard widgets. Mr. Hedges suggests the use of a shell script to check for the existence of the GrowlHelperApp before executing an AppleScript that passes Growl the necessary notification data (as specified on the official Growl website).

While this makes the process of Growl notifications via Dashboard apps much simpler for users such as myself, there are a few gotchas people need to be aware of. Mr Hedges states his need for Dashboard Growl integration as follows:

My use case was that users of my URL shortening widgets wanted to be able to exit Dashboard and be notified when the URL had been shortened and copied to the pasteboard.

What’s important to note here is not the task itself but the probability of multiple, repeated Growl notifications. You see, unlike Mr. Hedges URL shortening widget, Airmailr needs to be capable of sending multiple Growl notifications (more specifically, a Growl notification for each new tweet a user receives). In testing, I’ve noticed patchy behaviour on excessive use of this technique, often with a number of notifications passing the initial shell script test but never appearing on screen. I wonder, is there some sort of flood control mechanism built into Growl that I’m not aware of?

Secondly, it’s important to escape any quotation marks within the notification title and body elements. Otherwise you’re bound to see a few nasty, corrupted notifications.

Finally, I’ve yet to find a way to pass Growl any kind of meaningful application icons. Ideally, I’d like to use user avatars, but I’m not sure that Growl is capable of accepting remote URLs. The best I’ve managed to do is to supply Growl notifications sent in this manner with the default Dashboard icon.