Skip to content

lukestein/stata_ntfy

Repository files navigation

ntfy: Send notifications to ntfy.sh from Stata

ntfy is a lightweight Stata module to send push notifications to ntfy.sh using standard HTTP requests. This can be useful to notify you when long-running Stata jobs complete, or to alert you of errors. You can also use it to easily view graphs from Stata running on a server using your phone or desktop.

Just install the free ntfy app on your phone—no signups required—and you can receive notifications instantly.

Screenshot

It is designed to be platform-independent and dependency-light. It does not require Python or external plugins; it uses native system tools:

  • Mac/Linux: cURL (shell curl)
  • Windows: PowerShell (Invoke-RestMethod; experimental and untested!)

If you are worried about others seeing your notifications or spamming you with extra notifications, make sure to choose a secure topic name and read the ntfy.sh documentation.

Note: The code in this package was partly written by LLMs and I have tested it only on Mac and on Unix (specifically, the NBER server). I have not tested at all on Windows! Please open a github issue (or ideally a pull request) if you encounter any problems.

Installation

You can install the package directly from GitHub:

net install ntfy, from("https://raw.githubusercontent.com/lukestein/stata_ntfy/main") replace

Setup (Optional)

You can set a default topic so you don't have to type it every time. This saves the preference to your personal Stata directory.

ntfy_set my_secret_topic

To view the currently set default topic:

ntfy_get

Usage

1. Using a Default Topic

If you have run ntfy_set, you can just type a message:

ntfy "Regression analysis finished"

2. Explicit Topic

You can send to a specific topic (overriding the default) by providing it as the first argument:

ntfy other_topic "This goes to a different channel"

3. Advanced Options

Add titles, priorities, tags (emojis), or delays.

ntfy "Code failed to converge", title("Stata Error") priority(high) tags(warning)

4. Including Graphs

You can attach Stata graphs to your notifications:

sysuse auto, clear
scatter mpg weight

ntfy "Analysis complete", graph title("Results") tags(chart_with_upwards_trend)

For named graphs:

scatter mpg weight, name(myscatter)
ntfy "Check out this scatter plot", graphname(myscatter) width(800)

Note that the ntfy server only caches images for a limited time, so you may want to open your notification soon after sending it.

Syntax

ntfy [topic] ["message"] [, options]
Option Description
title(string) Bold title displayed at the top of the notification.
priority(string) Sets priority (min, low, default, high, urgent).
tags(string) Comma-separated emojis or tags (e.g., warning, tada).
delay(string) Schedule delivery (e.g., 10m, 9am, tomorrow).
topic(string) Explicitly specify the target topic (alternative to positional argument).
graph Include the most recent (topmost) graph as a PNG image.
graphname(string) Specify name of a graph to include (implies graph option).
width(integer) Width in pixels for exported graph (default: 1200).

Workflow Example

Use it to notify you of success or failure after a long job.

capture noise do my_analysis.do

if _rc == 0 {
    ntfy "Success: Model converged", tags(tada)
}
else {
    ntfy "Error: Script failed", tags(error) priority(high)
}

Alternatives

Inspired by statapush which uses Pushbullet, Pushover, or IFTTT rather than ntfy.sh

Author

Luke Stein

About

Stata command to send ntfy.sh push notifications with status updates and/or graphs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors