terminal-notifier 使用教程
1. 项目介绍
terminal-notifier
是一个命令行工具,用于在 macOS 上发送用户通知。这些通知功能在 macOS 10.10 及以上版本中可用。terminal-notifier
允许用户从命令行发送通知,支持自定义标题、副标题、声音、图标等选项。
项目地址:https://github.com/julienXX/terminal-notifier
2. 项目快速启动
2.1 安装
你可以通过 Homebrew 安装 terminal-notifier
:
brew install terminal-notifier
或者通过 RubyGems 安装:
sudo gem install terminal-notifier
2.2 基本使用
以下是一些基本的使用示例:
2.2.1 发送简单通知
terminal-notifier -message "Hello, World!"
2.2.2 自定义标题和副标题
terminal-notifier -title "ProjectX" -subtitle "new tag detected" -message "Finished"
2.2.3 使用自定义图标
terminal-notifier -title "ProjectX" -message "Finished" -appIcon http://example.com/icon.png
2.2.4 打开 URL 或应用
terminal-notifier -title "💰" -message "Check your Apple stock" -open "http://finance.yahoo.com/q?s=AAPL"
terminal-notifier -group 'address-book-sync' -title 'Address Book Sync' -subtitle 'Finished' -message 'Imported 42 contacts' -activate 'com.apple.AddressBook'
3. 应用案例和最佳实践
3.1 自动化任务通知
在自动化脚本中使用 terminal-notifier
可以方便地通知用户任务的完成情况。例如,在完成一个长时间的备份任务后,发送通知:
terminal-notifier -title "Backup" -message "Backup completed successfully!"
3.2 监控系统状态
你可以使用 terminal-notifier
来监控系统状态,并在出现问题时发送通知。例如,监控磁盘空间:
df -h | awk '$5 > 80 {print}' | terminal-notifier -title "Disk Space Warning" -message "Disk space is running low!"
3.3 集成到 CI/CD 流程
在 CI/CD 流程中,可以使用 terminal-notifier
来通知开发人员构建或测试的结果。例如,在 Jenkins 中配置一个构建后步骤:
terminal-notifier -title "Jenkins Build" -message "Build #1234 completed successfully!"
4. 典型生态项目
4.1 alerter
alerter
是另一个 macOS 通知工具,支持粘性通知和更多操作按钮。如果你需要这些功能,可以考虑使用 alerter
。
项目地址:https://github.com/vjeantet/alerter
4.2 terminal-notifier-web
terminal-notifier-web
是一个基于 Web 的界面,用于发送 terminal-notifier
通知。它提供了一个简单的 Web 界面来生成和发送通知。