From the moment AIR was released, a lot of developers were asking for Growl support to add toast style notifications. Up until now, there hasn’t really been an easy and flexible solution so most developers opted to build their own notifications. I really like Growl and the fact that you as a user have total control over the look and feel. I use the Mono style created by Christopher Lobay. It’s probably the sexiest toast style notification I’ve ever used.
With AIR 2 you can now call Growl right from within your application. I actually call the Growlnotify command-line tool, which comes as an extra in the Growl download. Most people probably don’t install these extras but that’s no problem. I can bundle the command-line tool as part of my application and call it directly from my applicationDirectory.
So… How does this work? It’s actually extremely easy… The first thing you do is set up a new File object that points to the Growlnotify tool.
var file:File = File.applicationDirectory;
file = file.resolvePath("growlnotify");
As I am going to bundle growlnotify with my application it will just be installed as part of the app and thus resides in applicationDirectory.
The next thing I have to do is set up a NativeProcessStartupInfo object. That’s where I’ll store the basic information that is used to start our NativeProcess.
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo(); var processArgs:Vector.<String> = new Vector.<String>(); processArgs[0] = "-n"; processArgs[1] = "My AIR application"; processArgs[2] = "-p"; processArgs[3] = "0"; processArgs[4] = "-t"; processArgs[5] = "Your Growl title"; processArgs[6] = "-m"; processArgs[7] = "Your Growl message"; processArgs[8] = "-a"; processArgs[9] = "Adobe AIR Application Installer"; nativeProcessStartupInfo.arguments = processArgs; nativeProcessStartupInfo.executable = file;
In this case, I’m also adding a bunch of arguments in my NativeProcessStartupInfo object. These arguments will be passed on to the growlnotify command-line tool. In this example, I’m setting up the name of my application, the notification priority, the title and message of my notification and I’m also telling it to use the icon associated with the Adobe AIR Application Installer. (Check out the Growlnotify docs for more info on these settings)
Next and last step is to actually call the native script.
process = new NativeProcess(); process.start(nativeProcessStartupInfo);
This code above will result in this Growl notification:
The only downside of using native scripts is that you’ll have to package your application specifically for the operating system you wrote your native script for. So in this case, I’d have to package it as a .DMG file since Growl only exists on OS X. That said, I really wouldn’t mind an OS X version of TweetDeck that allows me to use Growl instead of their custom notifications…
I really can’t wait to see what you guys are going to build with AIR 2! You can already start today! Check out Adobe Labs for more information!









dear serge, thanks for the pointing this possibility out. though, the user need to install growlnotify which requires at least some skill. i’d prefer a way to use the network socket of growl which allows to accept tcp and udp packets – this is easily configurable in the growl configuration pane.
by the way, there is still no way of forging udp packets with flash?
Couldn’t you detect the OS you’re running from and only use those native functions that are available to you? Packaging different versions of an AIR app seems kind of opposite to what AIR’s strengths are.
@Tom: The user doesn’t need to install anything. Growlnotify would be a part of the application installer and thus when the user installs the app, he also installs Growlnotify at the same time.
@Gilles: If you’re not using NativeProcess, the installation process is exactly the same as it was. One .AIR file that runs across Mac, Win, Linux and soon mobile. However, if you want to use NativeProcess, you’d have to package it as a native installer in order to use that capability.
Question: Why do you need to explicitly pack Air for Mac? I mean: Its possible to check using platform information if you are on mac/windows and then implement different strategies that deal with Growl or don’t do it. In other words: why has it to be a dmg?
Nice post Serge, thanks!
@Gilles, @Martin
The reasoning behind requiring OS-specific packages when using NativeProcess has been to maintain the cross-platform nature of an .air file. While, yes, a developer could (and should) verify the user’s OS prior to executing native processes, there is no guarantee that they will.
Installing a DMG or EXE presents a different “user contract” and explicitly informs the end user that they are installing an OS-specific application.
While I agree that this requirement is a bit of a burden, I can see Adobe’s desire to maintain the .air file format as strictly cross-platform.
@Martin Heidegger: In AIR 2.0 you can only use the NativeProcess class within AIR apps installed via native installers… Sad, I know.
@serge, well fair and easy enough. thanks for the hint. how about forging udp packets, though? :)
Thx man for this little great tutorial
Hi,
First of all: thanks for this great example. But being a JavaScript developer I wonder what this code would look like in JS. Specifically I am failing at the arguments part. It seems taht a regualr JS-array is no sufficient, I always get “convert”-errors when trying to execute…
Found a solution in the adobe forums:
In JavaScript you must not use a native array but isntead use this:
var processArgs = new air.Vector[""]();
all arguments can then be passed using push(), e.g.
processArgs.push(“-e”);
processArgs.push(“lfoo.bar.txt”);
I was wondering if you guy come some infomation/links to have i can build my own command line tools to the OS (Right now only mac) ?
But anyway yet a other great tutorial!
Best Regards
Dennis
Hey again,
When i build a test do i need to comple it to a package and then install before i can test it?
or can i include it in my project and test/debug it?
is it possible to get that information or downloadable project? maybe?
Vh,
Dennis
@Dennis: You can test your app in the same way as you test/debug other AIR apps. ADL allows you to use NativeProcess. So no need to package and install every time you made a change.
Okey, thanks – i am really trying with the Growlnotifyer but i am noget a ShellExpert and it same like i have not install it right?
Do you got some cool resources for shell/command line development?
hmm my english is getting worse sorry for that :)
Okey, thanks – i am really trying with the Growlnotifyer but i am not a Shell Expert and it seems like i have not installed it right?
Do you got some cool resources for shell/command line development?
Hallo again,
I what this to work – but i am getting some errors :
Error #3219: The NativeProcess could not be started. ‘Not supported in current profile.’
And if i am testing the : NativeProcess.isSupported – it´s false?
How do i fix this? :)
Hey Dennis,
Make sure your application descriptor file also has this node in it:
extendedDesktop
That should do the trick.
I’ll release this source as soon as AIR2 is released… Since we are still in beta, things may still change…
Serge
I saw this article, and wondered if the application has to be made with this function already, or could you add it.. (say as a user ) add it to tweetdeck for example…
also I wanted to point out that there is growl for windows..
http://www.growlforwindows.com/gfw/ (yes I use it )
@ NetNut404: The developer would have to add this to his app. The user cannot add it themselves.
That sounds like a great app! Ping me when it’s done!
Hey Serge,
Great tut .. thnx, I will use in our new AIR 2.0 application :-)
@ your question what will be build with AIR …
We are building a client software for flower-shops ( worldwide ) to transmit orders for Fleurop-Interflora…
It will be an AIR 2 application ( building in the BETA at this moment ) …
Thanks for all the knowledge you share, it is great to have an evangelist here in Belgium ;-)
Cheers
Jan