A minimalistic Java wrapper for Growl's notification system.
Your feedback is always welcome.
Example of an Growl4Java notification (theme).
- Mac OS X, with Growl (1.3+) installed
- Java version 6/7
First, import net.metzweb.growl.Growl;
and setup the Growl class.
The constructor requires three arguments:
- The name of your application.
- An array with all available notification types.
- An array with the enabled notification types.
Growl growl = new Growl("Java Weather",
new String[]{"General", "Warnings"},
new String[]{"General"});
Next, check whether Growl is available (installed and running). If this is the case, register the application.
if (growl.init()) {
growl.registerApplication();
}
Once our application is registered, we can start sending out messages. The first parameter of notify
is the used notification type, that has to be specified and enabled in the constructor.
growl.notify("General", "Weather", "Foggy");
If you want to add a fancy icon to your message, specify it as a third parameter:
growl.notify("General", "Weather", "Sunny", "/Users/foo/sun.png");
The icon path has to be an absolute path, which you can get like this:
File iconFile = new File("not/absolute/path/icon.png");
iconFile.getAbsolutePath();
Please note, that the icon will only appear if Growl notifications are used instead of Mountain Lion's notification center (it's not a limitation of the class).
Notification types allow you to group your messages by their purpose. This allows your users to manage your apps notifications by its type:
The type can be changed by modifying notify()
method's first parameter:
growl.notify("Warning", "Weather alert", "Thunder-storm");
boolean init()
: Initializes Java's AppleScript engine.void registerApplication()
: Adds application to Growl.void notify(<notification>, <title>, <message>)
: Sends notification.void notify(<notification>, <title>, <message>, <icon>)
: Sends notification with icon.
Growl4J 2.0 - 03/06/2013
update
Updated AppleScript commands for Growl 2.0+.feature
Implemented support for notification icons.feature
Added documentation.
Growl4J 1.0 - 15/01/2013
update
Compatible with Growl 1.3
Growl4J 0.5 - 10/01/2013
release
Beta version.
Copyright (c) 2013 - Programmed by Christian Metz
Based on Tobias Södergren Growlbridge, Apache License 2.0.
Released under the BSD License.