Mac OS Growl Notification System for Xojo apps

kuba - Sunday, 6 August 2017
Share:
Mac OS Growl Notification System for Xojo apps

Welcome again to our Xojo IDE tutorial adventure. This time we will learn how can we easily add to our Xojo application support for Growl Notification System. Because Xojo can execute AppleScript I will show you on this example how powerful this language can be.

AppleScript is a scripting language built into the Mac OS since System 7. It can be used to run an intelligent mechanism to control applications, and to access and modify data and documents. We will use it to display notification via Growl system.

To start we need to run Script Editor app. This will be the quickest way to create our script that will be used later on in our Xojo app. Script Editor can be found using Spotlight Search. Copy and paste the following code to Script Editor Windows and save the file as growl.


on run {growlDescription, growlTitle}

  tell application "Growl"

    set the allNotificationsList to ¬
      {"Notification"}


    set the enabledNotificationsList to ¬
      {"Notification"}


    register as application ¬
      "Our application name" all notifications allNotificationsList ¬
      default notifications enabledNotificationsList ¬
      icon of application "Safari"

    notify with name ¬
      "Notification" title ¬
      growlTitle description ¬
      growlDescription application name "Our application name"

  end tell

end run

It is easy to see that we have here two variables growlDescription and growlTitle. Those two values are needed to run the script. Now we need to copy the script "growl" to our project content using drag and drop. Move it to your project like any other file. The growl script will be now accessible as easily as Method in our Xojo app. To run it we will call it using this function.

growl("This is the description", "KubaDownload.com")

Now when we will need to notify our user we can use this anywhere in our code. Of course there is no problem to write our own solution for system notification, but this is something for different topic. Maybe I will show you how to create this kind of system in future.

Hope you enjoy this tutorial and if you appreciate the work I'm doing please left a comment.