怎样在macos命令行中弹出一个通知


在macos的命令行下执行裕兴时间较长的命令时,比如移动或拷贝大量数据,经常会忘记检查程序是否完成。于是想起来可以在命令执行结束后执行一个通知提醒的命令。

/usr/bin/osascript -e "display notification \" 提醒内容 \" with title \"提醒标题\""

实际使用时,直接将上述命令使用“&&”连接在任务命令之后即可。等任务结束,就会弹出通知。

还可以通过某个app弹窗。

osascript -e 'tell app "Finder" to display dialog "Hello World"'

用你想要的任何应用取代“Finder”。请注意,如果该应用程序背景消失,对话框也会显示在背景中。要始终在前台显示,请使用“系统事件”作为应用程序:

osascript -e 'tell app "System Events" to display dialog "Hello World"'

Archives