Accessing Growl via OS X Dashboard widgets

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.

2 Replies

Andrew Hedges Mar 29th '09

Hi Nial,

I’m not aware of any rate limits within Growl that would cause it to ignore notification requests. I assume Growl is implemented as a simple queue, so notifications would be queued up until the application had resources to display them. I know I’ve seen dozens of notifications come up when starting certain apps (iStumbler comes to mind). The more likely explanation is that Dashboard is having trouble running multiple instances of osascript through widget.system. This would be a great question for the Dashboard-Dev mailing list, on which several Apple engineers lurk.

Regarding the icon, yes this should be possible with some editing of the AppleScript. I did the simplest implementation and just used the Dashboard icon, but you should be able to access a file on the filesystem (within your widget) or pass it in as you say. I haven’t done this myself, but it’s all documented on the Growl website.

Good luck! I’m interested to see how your implementation shakes out.

-Andrew


Growl and OS X Dashboard widgets (cont’d) « Nial Giacomelli Mar 29th '09

[...] discussing Growl integration with OS X Dashboard widgets in my first article, I was lucky enough to hear back from Andrew Hedges, who suggested: The more likely explanation is [...]


Leave a comment

Sorry, the comment form is closed at this time.