tnr
A macOS notification library and CLI tool that provides a simple interface to send notifications using terminal-notifier.
Features
- đ¯ Simple and intuitive API
- đ§ Both CLI tool and Rust library
- ⨠Support for different notification types (error, warning, info, success)
- đ Clickable notifications with URL support
- đĩ Custom sounds for different notification types
- đĻ Zero external dependencies (except terminal-notifier)
Prerequisites
This tool requires terminal-notifier to be installed on your macOS system:
System Configuration
To use terminal-notifier, you need to configure macOS notification settings:
- Open System Preferences â Notifications
- Find and select terminal-notifier
- Check "Allow Notifications"
- Set notification style (Banner/Alert) as needed
Installation
As a CLI tool
As a library dependency
Add this to your Cargo.toml:
[]
= "0.1.0"
CLI Usage
# Basic notification
# Notification with title and type
# Notification with clickable URL
# Error notification
CLI Options
--title <TITLE>: Notification title--message <MESSAGE>: Notification message (required)--type <TYPE>: Notification type (error, warning, info, success)--url <URL>: URL to open when notification is clicked
Library Usage
use ;
Available Notification Types
Type::Error- â with "Sosumi" soundType::Warning- â ī¸ with "Funk" soundType::Info- âšī¸ with "Glass" soundType::Success- â with "Hero" sound
API Documentation
Notify
The main struct for creating and sending notifications.
Methods
new(message: impl Into<String>) -> Self- Create a new notification with a messagewith_title(self, title: impl Into<String>) -> Self- Set the notification titlewith_type(self, notification_type: Type) -> Self- Set the notification typewith_url(self, url: impl Into<String>) -> Self- Set a URL to open when clickedsend(&self) -> Result<(), TnrError>- Send the notification
Type
Enum representing different types of notifications with associated emojis and sounds.
Error Handling
The library uses TnrError enum for error handling:
TnrError::ExecutionFailed- terminal-notifier execution failedTnrError::CommandNotFound- terminal-notifier not found on system
Examples
See the examples/ directory for more usage examples.
License
MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.