Create Desktop Notifications From Stata or ... any Apps !!!

Create Desktop Notifications From Stata or ... any Apps !!!

The last article introduced how to create desktop notifications from R. In this article, I’ll show you how to create destop notifications from Stata or any other Apps!

Fist we need to know how does notifier work, As for Mac OS, it just loads terminal-notifier. So, let’s first explore the use of this command.

Install terminal-notifier

Shell
1
$ brew install terminal-notifier

View help infomation

Shell
1
$ terminal-notifier -help

sender ID parameter

This parameter is the Bundle ID of APP. So how to find it?

For example, we open RStudio.app, find a file named Info.plist:

You can find these two lines in Info.plist:

1
2
<key>CFBundleIdentifier</key>
<string>org.rstudio.RStudio</string>

org.rstudio.RStudio is RStudio’s Bundle ID. Another example is Stata15 SE:

1
2
<key>CFBundleIdentifier</key>
<string>com.stata.stata15</string>

sound parameter

We can find it in the system preference setting 👉 sound effects:

These are the parameters that can be used. Default parameter is default (I think the default notice voice is the clearest).

For example:

Shell
1
$ terminal-notifier -message "Stata 通知" -title "来自Stata的通知" -sound default -sender "com.stata.stata15"

Shell
1
$ terminal-notifier -message "Reeder通知" -title "来自Reeder的通知" -sound default -sender "com.reederapp.rkit2.mac"

Create desktop notifications from Stata

First let’s see where the terminal-notifier command is installed:

Shell
1
2
$ which terminal-notifier
/usr/local/bin/terminal-notifier

Then we can write a Stata command named notifier:

Stata
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
*! notifier: Create Desktop Notifications from Stata
*! Zhenxing Cheng
*! 2019-03-21
*! Examples:
*! notifier Hello World!
*! notifier Hello World!, sender(org.rstudio.RStudio)
*! notifier Hello World!, sender(org.rstudio.RStudio) sound(Ping)
capture program drop notifier
program define notifier
version 15.0
syntax [anything(name = notifier)], [TItle(string) SOUND(string) SENDER(string)]
if "`c(os)'" != "MacOSX" {
di as error "Your system isn't MacOSX!"
exit 702
}
if "`sound'" == "" local sound = "default"
if !(inlist("`sound'", "default", "Basso", "Blow", "Bottle", "Frog") | inlist("`sound'", "Funk", "Glass", "Hero", "Morse", "Ping") | inlist("`sound'", "Pop", "Purr", "Sosumi", "Submarine", "Tink")){
di "You choose a wrong sound option, the default is used!"
di "You can set sound option as default/Basso/Blow/Bottle/Frog/Funk/Glass/Hero/Morse/Ping/Pop/Purr/Sosumi/Submarine/Tink."
local sound = "default"
}
if "`title'" == "" local title = "Stata Notification"
if "`notifier'" == "" local notifier = "Your program has just run successfully."
if "`sender'" == "" local sender = "com.stata.stata15"
!/usr/local/bin/terminal-notifier terminal-notifier -message "`notifier'" -title "`title'" -sound "`sound'" -sender "`sender'"
end // end of program notifier

Use notifier in Stata programs

Stata
1
2
3
4
5
6
forval i = 1/100{
sleep 100
if `i' == 100{
notifier
}
}

# Stata

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×