Generating Dynamic Dock and System Tray Icons in AIR

Update (11/18/09): AIRPressure has been renamed to Timeslide. All links below have been update.

Someone asked me the other day if AIR applications can generate dynamic dock and system tray icons. The use case is something like Mail.app on Mac which always shows you the number of unread messages as part of the dock icon.

I’m happy to report that this is perfectly possible in AIR, and I created a sample application called AIRPressure to demonstrate. AIRPressure is a countdown timer which shows a dynamically generated timer icon in your dock or system tray to let you know how much time is left. It also has some other cool features:

  • It will optionally show a notification window when the timer is complete.
  • It will optionally open a URL in your browser when the timer is complete.
  • The dock icon bounces or the task bar icon flashes when the timer is complete.
  • All your settings are saved between uses.

The code for AIRPressure is probably more interesting than the application itself. For notifications (notification windows, bouncing the dock icon, flashing the task bar entry), and for changing the dock and system tray icons in a cross-platform manner, I use the as3notificationlib project that my team has been working on which makes it extremely simple. And for persisting preferences, I use the new as3preferencelib that my team also wrote which handles all file IO, encryption, and serialization automatically. AIRPressure is a pretty useful and comprehensive cross-platform application, and the entire app is only about 300 lines of code (thanks to all these libraries doing a lot of the heavy lifting).

19 Responses to Generating Dynamic Dock and System Tray Icons in AIR

  1. Cyril says:

    Really nice example which comes in handy in many projects. Thanks for sharing this ! 🙂

  2. Nice Christian! I wish there was a way to easily add text over the icon without having to draw it. This is pretty cool though.

  3. For those of us developing AIR apps using HTML/JS and don’t have Flash, can you create a compiled SWF of the two libs you’ve mentioned, as3notificationlib and as3preferencelib. Specically, I’d like to integrate the notification library into an app to make it easier to do notifications. It’d be nice to see app developers circle around a single implementation of something like this to make all AIR apps more consistent in their behaviour.

  4. I ended up downloading a trial version of Flash CS3 and after a few hours of trying to figure out how it all works, I compiled the notification lib into a SWF that I could use in my HTML project. Thanks a bunch!

  5. jaxon says:

    Where do i get the library’s mentioned above.The links send me to google code but the download section is empty!

  6. Barna says:

    Really nice work, am developing an air app as well right now, that’s how I found it. I had some problems regarding to dock icons’ bouncing in Leopard 10.5 (couldn’t get ’em bounce at all, wia no notification type)… I installed your app, the native windows worked properly, the icon changed, but no bouncing… Have you tested it on such OS? Am I doing sg. wrong, or is this a bug in AIR beta 2? If you come across sg. please drop me a line! Thanx for your time! Best regards: Barna

  7. Thijs says:

    Nice library, worked great on OSX 10.4.@jaxon: you need to download the code from the Subversion repository, looks like there’s no zip available.@jonathan snook: you can also use the free, soon to be open source, Flex SDK to compile the notification lib into a SWF

  8. sujon says:

    I tried to use this in my codebut the purr.as failed to import flash.desktop.DockIcon;flash.desktop.InteractiveIcon;flash.desktop.SystemTrayIcon;what could be the problemI am usingFLEX 3 BETA 2

  9. John Conley says:

    the libraries are not on Google – your links take me to emptiness..Are the lib’s somewhere on this site or elsewhere ??

  10. John, all the links are working fine for me. They link directly the projects on Google Code.

  11. sujon,All these libraries have been updated for beta 3 which will be available shortly. They are no longer compatible with beta 2. Sorry about that.Christian

  12. How difficult is it to remove the setInterval on the alert fadeout? For example, if you wanted the message to stay up until the user explicitly closed it.

  13. Hi Christian,i grabbed the latest version from the svn, whoever, you said that they are updated for beta3 but i get a RTE on Shell.shell. Can you tell me how to update this?Thanks,Sidney

  14. Sunil says:

    Hi,Totally off the wall question: What is the meaning of the name of the Purr class in your awesome as3notificationlib? 🙂

  15. Sunil,When I started the framework, I was planning on building something similar to Growl on OS X — hence the name Purr. :)Christian

  16. Paul Haddon says:

    Neither the .air nor .zip files are currently available.Both return 404 error page notices.

  17. Christian Cantrell says:

    @Paul: Thanks for the heads-up. These files didn’t get moved the last time my blog was migrated. I just updated the links.

  18. the source code link is down 🙁

  19. Christian Cantrell says:

    Sheesh. Updated the link again. Sorry about that.