如何从终端清除通知中心?

cwd*_*cwd 5 terminal notifications osx-mountain-lion osx-mavericks macos

我真的很喜欢终端通知程序以及它如何允许您将内容发送到通知中心。

它甚至有一个方便的功能来删除它发送的通知,例如,如果我从另一个应用程序(如 CodeKit)欺骗通知,语法是:

terminal-notifier -sender com.incident57.CodeKit -remove ALL
Run Code Online (Sandbox Code Playgroud)

但我猜这个应用程序无法清除它未发送的通知,因为其他消息仍然存在:

屏幕截图带阴影.png

这是一个很棒的工具,但它仍然让我想知道:

如何从终端清除通知中心?

Lri*_*Lri 3

您可以像这样运行 AppleScript:

osascript -e 'tell application "System Events" to tell process "Notification Center"
    click menu bar item 1 of menu bar 2
    delay 0.1
    repeat while exists button 1 of UI element 1 of row 2 of table 1 of scroll area 1 of window 1
        click button 1 of UI element 1 of row 2 of table 1 of scroll area 1 of window 1
    end repeat
    click menu bar item 1 of menu bar 2
end tell'
Run Code Online (Sandbox Code Playgroud)

  • 在 10.8 上,我得到“75:110:执行错误:系统事件出错:无法获取进程“通知中心”的菜单栏 2。索引无效。(-1719)” (3认同)