Using
AppleScript
to
produce
Growl
notifications from LWC triggers
Introduction: Lightsoft Weather Center provides a powerful set of tools to convert weather events into actions on your Mac. Unfortunately, many things require human intervention, and LWC doesn't have such an easy time getting your attention. Alas, it turns out that putting up some sort of dialog is more complicated than you would expect, because normally dialogs require an immediate response - suppose the weather event happens while you are away from your computer? A group of developers realized that another framework for notifying users was needed and invented Growl (http://growl.info). Growl puts up windows like dialog boxes, but they don't need an immediate action. Most commonly they simply disappear after a few seconds. This can be useful for example if you are listening to music and want to know what the selection is. Growl does this with a little window like the following: ![]() The Growl framework has one more feature that could be very handy to folks running LWC on a dedicated computer. It can forward Growl notifications from one Mac to another. So weather-related notifications can appear on the computer you normally use. The only "problem" is that LWC doesn't support Growl directly. However, Growl notifications can be very easily generated using AppleScript. In turn, LWC can launch an AppleScript that has been saved as an application. What follows is a quickie tutorial on creating your very own Growl notifications from LWC using AppleScript. Installing Growl: Growl is free software (although they do ask for donations.) It can be downloaded from the Growl site above and installed according to their instructions. Growl comes with some sample programs that can be used to test if your installation is working. In particular, the program HardwareGrowler can be used to see if USB devices like your mouse or keyboard have been plugged or unplugged. Once you have installed Growl, you can run HardwareGrowler and then test your Growl installation by unplugging your mouse and plugging it back in. HardwareGrowler does work with some Weather Station hardware (such as the Davis USB connection,) so it might be useful for troubleshooting. Growl is a system preference and has lots of options. Take a little time to familiarize yourself with all the options. In particular, take the time to choose a display option default style that works well with your desktop background. The examples in this tutorial use the NotifyOSX style. ![]() Sample AppleScripts to create Growl notifications: Once you have Growl installed, you can use AppleScript to produce Growl notifications that LWC can launch for a weather-related alert. Do to this, launch the application: Script Editor that you will find in the AppleScript folder inside your applications folder. You can then download this AppleScript template (LWC Growl trigger) that is also shown below and then adjust to your needs:
Yes, this will look like programming and that might be enough to strike terror into some folks, but worry not, this truly isn't difficult. The only thing you'll never need to change are the four text fields shown in bold-italics: Weather event title, Weather event description, and the two instances of LWC Growl trigger. The first two text fields . . . are exactly what they say: the title of your notification, and the text describing your notification. If you decide to create additional scripts (or even rename this one,) you'll need to change the filename in the script at the two locations noted by LWC Growl trigger (details are below.) Using the Script Editor, open the file "LWC Growl trigger" that you can download above and try changing these two fields into: LWC reports clear skies and LWC is detecting clear sky conditions. An example of these changes is shown in the Script Editor window below (changes highlighted in orange:) ![]() To make sure everything is working properly, try pressing the Run button at the top left of the window. It should produce a Growl notification similar to this: ![]() Odds are that you'll soon notice something different about the Growl notification you have just made - it doesn't go away! Instead, it just sits there. Don't panic, this script creates "sticky" Growl notifications. To "get rid of it" you need to dismiss it explicitly by pressing on the close button that is somewhere around the upper-left corner. On this style of notification the dismiss button looks like this when you bring your mouse cursor nearby: ![]() Creating sticky Growl notifications makes good sense when you are creating alerts that are infrequent and could happen when you are away from the computer. Don't like "sticky?" Worry not, there are instructions on taking the "stick" out of your own Growl notification scripts further down in this document. When you are satisfied with the overall message, you need to save it as an application that LWC can launch for a weather alert. To do this, you need to use the Save As option from the Script Editor. It is important to have the options for saving set correctly. As illustrated below (and highlighted in orange) the File Format must be Application and all the options should be unchecked - especially the Startup Screen option. ![]() Once you have saved your AppleScript as an application, you can test it by double-clicking on it. It should produce the same Growl notification as shown above and quit having no other visible behavior. This is a good time to create an organized place for your scripts associated with LWC - certainly something more tidy than the Desktop! The final step is to modify the LWC preferences to run this AppleScript when (in this case) clear sky conditions are detected by LWC. This is done from the Alerts pane of the LWC preference window: ![]() Click on the orange highlighted Set Item button to locate your Application in your file system with this alert. Don't forget to check the Launch User Item checkbox, or nothing will happen even if you have provided an application. Now all you have to wait for is - clear skies!! Creating additional scripts: Now that you have the basic scheme, what is going to stop you from creating additional scripts for other weather-related alerts? It is "almost" as easy as firing up the Script Editor and saving this prototype script under a different filename. If you test your new creation - it will work fine. However, there is a catch. Growl won't recognize it as something new. If you look at the Growl applications list, your new creation won't be listed. That means you cannot configure it independently of the original script: LWC Growl trigger. If you are going to create a new script, you should change the name in the script at the two places where the example script's filename: LWC Growl trigger appears in the code. They are shown in bold-italic in the section above that describes what text needed to be edited in this example. As long as you have the actual filename of your script in the code as noted above - everything will work fine. In addition to the 3 "standard alerts" that can be configured from the preference pane above. You can create a myriad of custom alerts. See the LWC manual for details on configuring custom alerts. You can then attach customized AppleScripts in essentially the same way as has been shown here. It might be much easier to do some testing with custom alerts than wait for clear skies, rain, or icy conditions! Taking out the "stick" out of your notifications: Now that you are brimming with confidence, perhaps you'll want to do some customizing. There may be times when a "sticky" notification isn't appropriate. If you look at the text of the script, you can take out the "stick" by removing the words: with sticky at the end of the line that starts with: notify with name (almost completely at the bottom.) Conclusion: AppleScript is a powerful development environment, and the capacity of LWC to launch AppleScripts gives you far greater power to do weather-related things than probably you have the hardware to implement. Even when it comes to getting your attention, just-about any sort of user-interaction dialogs can be invoked using AppleScript. So if you need to be "hit over the head" because the weather has changed, AppleScript can probably accommodate. Growl represents a balanced compromise for making such announcements. It is particularly forgiving of some of the surprises that a beginner might otherwise get caught with. While Growl is not part of the Mac OS, it installs easily and has been gaining acceptance among developers. So it is a reasonable point of departure. You might want to further embellish these scripts. One obvious addition might be the time when a notification occurred. That way if you come back to your computer, you'll know how long ago the weather-related event started. The only limitation of the way AppleScript is launched from LWC, is that you cannot "read values" from LWC into your AppleScripts. Still, once LWC has got your attention, you can refer back to the LWC yourself and decide what the actual conditions require you to do. One aesthetic addition might be to add an icon other than the AppleScript icon shown in the corner. This is extremely easy to do and works fine if you don't need an notifications sent over a network. Unfortunately, trying to use AppleScript to send notifications over a network with an icon causes a crash in present implementations of Growl. A fix is in the works, but for now, icons probably should be avoided. I hope that you find this technique interesting and perhaps an introduction into harnessing this very powerful feature of LWC! |