Macotron

macotron.notify

Post a system notification banner, or flash a short toast on the screen under the pointer.

macotron.keyboard.on("Copy date", "cmd+shift+d", () => {
  const today = new Date().toLocaleDateString();
  macotron.clipboard.set(today);
  macotron.notify.toast("Copied", today, { color: "success" });
});

Toasts

toast(title: string, body?: string, opts?: ToastOptions): void

Shows a small HUD centered near the bottom of the screen under the pointer, 48 points from the edge, then fades it out. The title and body show as one line, "Title: body", and long text wraps. Only one toast shows at a time; a new toast replaces the current one. You can also call toast(title, opts) with no body.

OptionTypeWhat it does
position"top" | "bottom"Which edge of the screen. Default "bottom".
durationnumberHow long it stays, in milliseconds. Default 3000.
colorstring"info" (the default: plain text, no icon), "success" or "green" (green check), "error", "failure" or "red" (red cross), "warning" or "orange" (orange triangle). "blue", "yellow" and #RRGGBB tint only the sfSymbol icon and leave the text in the normal color.
sfSymbolstringAn SF Symbol to show before the text, in place of the color's default icon.

Write the title as the feature name and the body as the message: toast("Layouts", "Saved 3 windows"). For a bare state, continue the title in lowercase: toast("Night vision", "off").

Notifications

show(title: string, body: string, opts?: { sound?, subtitle?, id?, url? }): void

Posts a banner through Notification Center. Banners show even while Macotron is the active app. Throws a TypeError when title or body is missing, or when url does not parse.

OptionTypeWhat it does
soundbooleanPlay the default notification sound. Default true.
subtitlestringA line between the title and the body.
idstringPosting again with the same id replaces the earlier notification instead of adding another.
urlstringOpens when the user clicks the banner. The URL is stored in the notification, so the click works even after Macotron restarts.

The first banner asks for notification permission. If the user denies it, banners are dropped without an error. The user can turn them back on in System Settings > Notifications > Macotron. Toasts need no permission.

macotron.notify.show("Pomodoro", "Break — 5 minutes", { id: "pomodoro" });

See also