Forked from aaronjgreenberg/terminal-notifier.py
Last active
December 26, 2015 04:19
-
-
Save zachguo/7091639 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "terminal-notifier" should be installed first | |
import subprocess | |
subprocess.check_call('terminal-notifier', '-title', 'title content here', '-message', 'message content here') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "terminal-notifier" should be installed first | |
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") != "") | |
if (in.rstudio) { # hack to see if running in RStudio | |
title <- "RStudio" | |
sender <- activate <- "org.rstudio.RStudio" | |
} | |
if (in.rgui) { # running in R GUI app? | |
title <- "R GUI" | |
sender <- activate <- "org.R-project.R" | |
} | |
# if running in RStudio or R GUI app use NotificationCenter otherwise use message() | |
if ((in.rstudio | in.rgui) & in.osx) { | |
system(sprintf("/usr/bin/terminal-notifier -title '%s' -message '%s' -sender %s -activate %s", | |
title, msg, sender, activate ), | |
ignore.stdout=TRUE, ignore.stderr=TRUE, wait=FALSE) | |
} else { | |
message(msg) | |
} | |
} | |
# try it! | |
# library(source.gist) # install.packages("source.gist") | |
# source.gist(6545433) | |
# system("sleep 10") | |
# notify("Long op complete") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment