Using Growl in AIR applications with AIR 2 NativeProcess

The AIR2 release is just around the corner and one of my favorite new features is the ability to use native scripts. As I’ve already demonstrated earlier, this is extremely powerful and here’s another good example.

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!

Tags: , , , , , , ,

50 Responses to “Using Growl in AIR applications with AIR 2 NativeProcess”

  1. tom 15. Mar, 2010 at 11:52 am #

    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?

  2. Gilles Vandenoostende 15. Mar, 2010 at 12:00 pm #

    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.

  3. Serge Jespers 15. Mar, 2010 at 12:14 pm #

    @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.

  4. Serge Jespers 15. Mar, 2010 at 12:15 pm #

    @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.

  5. Martin Heidegger 15. Mar, 2010 at 1:06 pm #

    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?

  6. Sven 15. Mar, 2010 at 2:15 pm #

    Nice post Serge, thanks!

  7. Chris Deely 15. Mar, 2010 at 3:28 pm #

    @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.

  8. Quentin 15. Mar, 2010 at 3:32 pm #

    @Martin Heidegger: In AIR 2.0 you can only use the NativeProcess class within AIR apps installed via native installers… Sad, I know.

  9. tom 15. Mar, 2010 at 4:16 pm #

    @serge, well fair and easy enough. thanks for the hint. how about forging udp packets, though? :)

  10. Tripi 17. Mar, 2010 at 4:02 pm #

    Thx man for this little great tutorial

  11. Michael 19. Mar, 2010 at 1:08 pm #

    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…

  12. Michael 19. Mar, 2010 at 7:31 pm #

    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”);

  13. Dennis 20. Mar, 2010 at 3:40 pm #

    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

  14. Dennis 21. Mar, 2010 at 12:48 pm #

    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

  15. Serge Jespers 22. Mar, 2010 at 9:17 am #

    @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.

  16. Dennis 22. Mar, 2010 at 3:46 pm #

    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?

  17. Dennis 22. Mar, 2010 at 3:58 pm #

    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?

  18. Dennis 23. Mar, 2010 at 10:21 am #

    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? :)

  19. Serge Jespers 23. Mar, 2010 at 10:31 am #

    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

  20. NetNut404 23. Mar, 2010 at 11:28 am #

    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 )

  21. Serge Jespers 23. Mar, 2010 at 5:08 pm #

    @ NetNut404: The developer would have to add this to his app. The user cannot add it themselves.

  22. Serge Jespers 01. Apr, 2010 at 5:07 pm #

    That sounds like a great app! Ping me when it’s done!

  23. Jan VH 01. Apr, 2010 at 7:04 pm #

    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

Trackbacks/Pingbacks

  1. Ilja Segeda - 15. Mar, 2010

    RT @sjespers: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  2. fabianv - 15. Mar, 2010

    RT @sjespers: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  3. topsy_top20k - 15. Mar, 2010

    Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  4. Koen Phlips - 15. Mar, 2010

    RT @sjespers: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn #osx #air

  5. kajorn - 15. Mar, 2010

    Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn by @sjespers

  6. Methas Tariya - 15. Mar, 2010

    RT @kajorn: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn by @sjespers

  7. Simon Barber - 15. Mar, 2010

    RT @sjespers: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  8. Leo van Hamond - 15. Mar, 2010

    Using Growl in AIR applications with AIR 2 NativeProcess: The AIR2 release is just around the corner and one of my… http://bit.ly/avI0PU

  9. Adobe User Group XL - 15. Mar, 2010

    RT @vanHamond: Using Growl in AIR applications with AIR 2 NativeProcess: The AIR2 release is just around the corner and one of my… http://bit.ly/avI0PU

  10. Svetoslav Sotirov - 15. Mar, 2010

    RT @sjespers: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  11. Flash Lounge - 15. Mar, 2010

    RT @sjespers: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  12. HowDo.us - 15. Mar, 2010

    Using Growl in AIR applications with AIR 2 NativeProcess: The AIR2 release is just around the corner and one of my… http://bit.ly/dfX6zM

  13. barbietunnie - 15. Mar, 2010

    RT @sjespers: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  14. Joseph Labrecque - 15. Mar, 2010

    Another great NativeProcess example! RT @sjespers: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  15. Sven Peeters - 15. Mar, 2010

    Reading: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/cEFE8I

  16. yugioh2500 - 15. Mar, 2010

    RT @kajorn: Blogged: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn by @sjespers

  17. Gilles Guillemin - 15. Mar, 2010

    Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/dAn16v

  18. matiere* - 15. Mar, 2010

    Using Growl in AIR applications with AIR 2 NativeProcess | Serge Jespers http://bit.ly/crxfFY

  19. Adobe Flex News - 15. Mar, 2010

    Using Growl in AIR applications with AIR 2 NativeProcess:
    The AIR2 release is just around the corner and one of m… http://bit.ly/9Gybxr

  20. Francesco Marconi ? - 15. Mar, 2010

    RT @sjespers: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  21. Michael Ritchie - 15. Mar, 2010

    Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/dAn16v (via @gillesguillemin) [been waiting for this!]

  22. Simon - 16. Mar, 2010

    Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/bx7kGs

  23. Xavi Gimenez - 18. Mar, 2010

    Using Growl in AIR applications with AIR 2 NativeProcess – http://bit.ly/dlWe5Y

  24. joseeight - 18. Mar, 2010

    using Growl in AIR 2 – http://tr.im/Sn3f

  25. Abraham Vázquez - 18. Mar, 2010

    RT @joseeight: using Growl in AIR 2 – http://tr.im/Sn3f

  26. articG - 18. Mar, 2010

    RT @sjespers: Using Growl in AIR applications with AIR 2 NativeProcess http://bit.ly/9v8RLn

  27. Nuevas versiones Adobe AIR 2 y Flash Player 10.1 – No Smoke - 11. Jun, 2010

    [...] Using Growl in AIR applications with AIR 2 NativeProcess por Serge Jespers [...]

Leave a Reply