Growl Java wrapper

22 views
Skip to first unread message

quen

unread,
Feb 9, 2008, 2:27:20 PM2/9/08
to Growl Discuss
Hi,

I'm just starting work to add Growl support to my Java app.

The existing Java binding is a bit of a pain to use - it uses the
deprecated-since-10.4 Cocoa bridge, which means it won't compile by
default in an IDE, and won't even link (will cause the application to
die horribly) if any application that mentions the class is run on a
non-Mac platform.

After a false start with the network support (this looks difficult to
use and is anyway disabled by default, which I presume probably
applies even to connections from localhost), I decided the easiest
thing to do was use AppleScript. It's pretty easy to run AppleScript
from Java by using the 'osascript' command-line tool.

The result is a very simple pure Java wrapper for Growl which can be
used straight away on multi-platform apps without breaking anything.
(If you run on another platform, or with Growl not installed, it
doesn't do anything.)

After I'd written it, I thought in case you don't already have a
similar improvement, maybe I'd contribute it back to the project -
maintainers should feel free to include it in future SDK versions if
desired. (Or an improved version - it doesn't support many features,
the most significant omission being that you can only specify icons by
the name of a program, because that's what I happened to want.)

http://live.leafdigital.com/temp/GrowlWrapper.zip - includes single
source/class file, jar file for convenience, and javadoc.

I haven't tested on anything other than my own computer (10.5), and to
be honest not much there yet, but as far as I can tell osascript has
been around since day, so it should work everywhere.

Here's the usage example from the javadoc:

String FUN_NOTIFICATION="Fun notification",
BORING_NOTIFICATION="Boring notification";
GrowlWrapper gw=new GrowlWrapper("MyApp","Finder",
new String[] {FUN_NOTIFICATION,BORING_NOTIFICATION},
new String[] {FUN_NOTIFICATION});
gw.notify(FUN_NOTIFICATION,
"Fun stuff","I bet you're glad you can see this!");
gw.notify(BORING_NOTIFICATION,
"Boring stuff","I bet you regret seeing this!");

--quen

Christina Cohen

unread,
Mar 28, 2008, 9:36:48 AM3/28/08
to Growl Discuss
http://wikipedlla.com/growl_java_wrapper
>  String FUN_NOTIFICATION="Fun notification",
>    BORING_NOTIFICATION="Boring notification";
>  GrowlWrapper gw=new GrowlWrapper("MyApp","Finder",
>    new String[] {FUN_NOTIFICATION,BORING_NOTIFICATION},
>    new String[] {FUN_NOTIFICATION});
>  gw.notify(FUN_NOTIFICATION,
>    "Fun stuff","I bet you're glad you can see this!");
>  gw.notify(BORING_NOTIFICATION,
>    "Boring stuff","I bet you regret seeing this!");
> --quen
Reply all
Reply to author
Forward
0 new messages