Skip to content

Instantly share code, notes, and snippets.

@emraher
Last active April 12, 2016 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emraher/1867e024f74a80a736b1f5981349ed88 to your computer and use it in GitHub Desktop.
Save emraher/1867e024f74a80a736b1f5981349ed88 to your computer and use it in GitHub Desktop.
Send Growl notifications from R (RStudio, R GUI or R console) - Requires growlnotify / Similar to https://goo.gl/dtP4eH
growl.notify <- function(msg = "Operation complete") {
in.osx <- (Sys.info()['sysname'] == "Darwin")
in.rstudio <- (Sys.getenv("RSTUDIO") == "1")
in.rgui <- (Sys.getenv("R_GUI_APP_REVISION") != "")
dir.notifier <- system("which growlnotify", intern = TRUE)
if (in.rstudio) { # hack to see if running in RStudio
title <- "RStudio"
}
if (in.rgui) { # running in R GUI app?
title <- "R"
}
# if running in RStudio or R GUI app use Growl otherwise use message()
if ((in.rstudio | in.rgui) & in.osx) {
system(paste(dir.notifier, "--appIcon", title, title, "-m '", msg, "'", sep = " "),
ignore.stdout = TRUE, ignore.stderr = TRUE, wait = FALSE)
} else {
message(msg)
}
}
# try it!
# if ((Sys.info()['sysname'] == "Darwin")) {devtools::source_gist("1867e024f74a80a736b1f5981349ed88")}
# system("sleep 10")
# growl.notify("Long op complete")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment