Growl in R and Stata

January 20, 2011 at 5:10 am 10 comments

| Gabriel |

Growl is a system notification tool for Mac that lets applications, the system itself, or hardware display brief notification, usually in the top-right corner. The translucent floating look reminds me of the more recent versions of KDE.

Anyway, one of the things it’s good for is letting programs run in the background and let you know when something noteworthy has happened. Of course, a large statistics batch would qualify. I was running a 10 minute job in the R package igraph and got tired of checking to see when it was done so I found this tip. In a nutshell, it says to download Growl, including the command-line tool GrowlNotify from the “Extras” folder, then create this R function.

growl <- function(m = 'Hello world')
system(paste('growlnotify -a R -m \'',m,'\' -t \'R is calling\'; echo \'\a\' ', sep=''))

Since the R function “system()” is equivalent to the Stata command “shell,” I realized this would work in Stata as well and so I wrote this ado file.* You call it just by typing “growl”. It takes as an (optional) argument whatever you’d like to see displayed in Growl, such as “Done with first analysis” or “All finished” but by default displays “Stata needs attention.” Note that while Stata already bounces in the dock when it completes a script or hits an error, you can also have Growl appear at various points during the run of a script.

I’ve only tested it with StataMP, but I’d appreciate it if people who use Growl and other versions of Stata would post their results in the comments. If it proves robust I’ll submit it to SSC.

Here’s the Stata code. The most important line is #32 and if you were doing it by hand you’d do it as a one-liner but the rest of this stuff allows argument passing and compatibility with the different versions (small, IC, SE, MP) of Stata:

*1.0 GHR Jan 19, 2011
capture program drop growl
program define growl
	version 10
	set more off
	syntax [anything]

	if "`anything'"=="" {
		local message "Stata needs attention"		
	else {
		local message "`anything'"
	local appversion "Stata"
	if "`c(flavor)'"=="Small" {
		local appversion "smStata"
	else {
		if `c(SE)'==1 {
			if `c(MP)'==1 {
				local appversion "StataMP"
			else {
				local appversion "StataSE"
		else {
			local appversion "Stata"
	shell growlnotify -a `appversion' -m \ "`message'" \ `appversion' \

*Most programming/scripting languages and a few GUI applications have a similar system call and you can likewise get Growl to work with them. For instance, Perl also has a function called system(). In shell scripting of course you can just use the “growlnotify” command directly.

Entry filed under: Uncategorized. Tags: , , .

Diacriticals in Zotero and Bibtex Shufflevar update


  • 1. D. Woods  |  January 20, 2011 at 5:23 am

    This is great stuff! I’ve got some big R jobs coming up and I’m going to put it this to work right away!

  • 2. Kieran  |  January 21, 2011 at 7:55 am


  • 3. Nick Cox  |  January 21, 2011 at 8:19 am

    For Stata:

    I’d put in early traps with informative error messages if the user is
    not using a Macintosh (check c(os)) or if growl is not installed. I wouldn’t underestimate the ability of a small tail of users not to read your help file carefully.

    • 4. gabrielrossman  |  January 21, 2011 at 11:29 am

      good point and something i’ll add to it when i have another half hour. the c(os) thing would be easy but i’d also like to confirm that the command-line tool “growlnotify” is installed as i think this will be a more common user mistake. this latter issue will be a little harder to code, which is why i haven’t done it yet. fortunately, somebody posted a way to do this in the comments to the R blog post i linked,, which i could work into the R code and adapt to the Stata code (which might be hard as it requires capturing output from shell).

  • 5. Eric Booth  |  January 22, 2011 at 4:45 pm

    My first thought when I saw this post was that Stata is already a registered application with Growl. However, I forgot that I had turned off Growl notification for Stata 10, so I didn’t notice that since I’ve upgraded to Stata 11 MP it is no longer a registered Growl application.
    That is, Growl works with Stata 10 on the Mac by default — it notifies you when a do-file had finished as well as errors and you can customize the notifications, sounds, and messages from the Growl preferences panel in System Preferences (it can also forward Growl messages to other machines).
    However, according to this Growl page ( applications must register with Growl – you cannot add them to the list. So, it appears that Stata Corp has removed the Growl registration for Stata 11 (unless I missed something about that during the install (?)

    • 6. gabrielrossman  |  January 22, 2011 at 5:29 pm

      interesting. i’ve only started using Growl recently (as a result of the R batch described above) so i didn’t know that this used to work out of the box. wonder why they stopped supporting it?

  • 7. Chinh Nguyen  |  April 25, 2011 at 12:28 pm

    Growl support was removed because:

    1) At the time 64-bit support was first added to Stata, there was no 64-bit version of Growl which meant it could not be supported by the 64-bit version of Stata.

    2) growlnotify is more than adequate. As a matter of fact, I’ve been using it since Stata 10 (maybe even 9). I have lots of different Macs that I run certification scripts on and they send growl notifications to my main Mac so that I can see where their at or if there’s a problem.

    • 8. gabrielrossman  |  April 25, 2011 at 12:38 pm

      thanks for the info on this. also, thanks for improving the PDF “graph export” in 11.2

      • 9. Jeremy  |  December 14, 2011 at 8:21 pm

        Thanks for this code. I found I was getting “command not found” errors when running the growlnotify shell command in stata 12 on mac osx, but adding the full directly line (e.g. ” ! /usr/local/bin/growlnotify”) fixed the problem. So, Stata 12 for Mac (at least) requires knowing precisely where growlnotify is. 🙂

      • 10. gabrielrossman  |  December 15, 2011 at 5:08 am

        weird. I’m using Stata 12 on OS X 10.6 and it works as described in the post.
        anyway, glad you were able to get it working

The Culture Geeks

%d bloggers like this: