Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
alerter_rs
A Rust wrapper around vjeantet/alerter — send rich macOS user notifications from Rust without the user needing to install other programs in advance (and without having to create a bundled application).
The alerter binary is compiled from source at build time and embedded directly into your Rust binary. Users of your application never need to install alerter separately.
Requirements
- macOS 13+
- Swift toolchain (included with Xcode Command Line Tools)
- Rust 1.56+ (2021 edition)
Installation
Add to your Cargo.toml:
[]
= "26.5"
Usage
Send a notification
use Alerter;
let response = new
.title
.subtitle
.sound
.send?;
println!;
Actions and dropdowns
let response = new
.actions
.dropdown_label
.send?;
Reply notifications
let response = new
.reply
.send?;
if let Some = response.activation_value
JSON output
let response = new
.json
.send?;
Scheduled delivery
// Deliver after 30 seconds
new.delay.send?;
// Deliver at a specific time
new.at.send?;
Custom appearance
new
.title
.sender // appear as Safari
.app_icon
.content_image
.close_label
.timeout // auto-close after 10s
.ignore_dnd // bypass Do Not Disturb
.group // replace previous in group
.send?;
Non-blocking (async) notifications
send_async() spawns the notification subprocess and returns immediately with a NotificationHandle, letting your program continue without waiting for user interaction.
Fire and forget
use Alerter;
// Notification shows, handle is dropped, subprocess is killed
new
.title
.send_async?
.detach; // detach so the notification persists after drop
Deferred wait
let handle = new
.actions
.send_async?;
// ... do other work while notification is showing ...
let response = handle.wait?;
println!;
Managing multiple concurrent notifications
let mut handles = vec!;
// Poll and reap completed notifications
while !handles.is_empty
Manage notifications
use Alerter;
// Remove notifications by group
remove?;
// List notifications by group
let info = list?;
// List all
let all = list?;
API Reference
Alerter
| Method | Description |
|---|---|
new(message) |
Create a new notification with a message (required) |
title(&str) |
Notification title (default: "Terminal") |
subtitle(&str) |
Notification subtitle |
sound(&str) |
Sound name ("default" for system sound) |
actions(Vec<&str>) |
Action buttons (comma-separated in dropdown if multiple) |
dropdown_label(&str) |
Label for the actions dropdown |
reply(&str) |
Show reply field with placeholder text |
close_label(&str) |
Custom close button label |
group(&str) |
Group ID for notification replacement |
sender(&str) |
Bundle ID to impersonate (default: com.apple.Terminal) |
app_icon(&str) |
URL or path for app icon image |
content_image(&str) |
URL or path for attached image |
timeout(u32) |
Auto-close after N seconds |
json(bool) |
Output as JSON |
delay(u32) |
Deliver after N seconds |
at(&str) |
Deliver at time ("HH:mm" or "yyyy-MM-dd HH:mm") |
ignore_dnd(bool) |
Send even if Do Not Disturb is on |
send() |
Send the notification (blocking), returns Result<AlerterResponse, AlerterError> |
send_async() |
Send the notification (non-blocking), returns Result<NotificationHandle, AlerterError> |
remove(group_id) |
Remove notifications by group ID |
list(group_id) |
List notifications by group ID (or "ALL") |
NotificationHandle
| Method | Description |
|---|---|
wait(self) |
Block until the notification exits, returns Result<AlerterResponse, AlerterError> |
try_wait(&mut self) |
Poll without blocking, returns Ok(None) if still running |
detach(self) |
Consume the handle and let the subprocess continue independently |
Dropping a NotificationHandle without calling detach() kills the subprocess.
AlerterResponse
| Field | Type | Description |
|---|---|---|
activation_type |
String |
What happened: @CONTENTCLICKED, @CLOSED, @TIMEOUT, or an action label |
activation_value |
Option<String> |
Reply text (when using reply notifications) |
AlerterError
| Variant | Description |
|---|---|
BinaryExtraction(String) |
Failed to extract the embedded binary |
ProcessSpawn(String) |
Failed to spawn the alerter process |
Runtime(String) |
Alerter returned a non-zero exit code |
How it works
- Build time:
build.rsrunsswift build -c releaseon the vendoredalerter/submodule - Embedding: The compiled binary is included via
include_bytes! - Runtime: On first use, the binary is extracted to
~/Library/Caches/alerter_rs/with a SHA256-based filename for cache invalidation - Invocation: Each API call spawns the cached binary as a subprocess with the appropriate CLI flags
Versioning
The crate version mirrors the bundled alerter version (e.g., alerter v26.5 = crate 26.5.x).
License
This crate wraps alerter by Julien Blanchard (vjeantet), which is licensed under the MIT License.