删除节点通知器中的terminal图标

我正在使用https://github.com/mikaelbr/node-notifier包在shell中显示通知。

这是我的代码:

var notifier = require('node-notifier'); var path = require('path'); notifier.notify({ title: 'My awesome title', message: 'Hello from node, Mr. User!', icon: path.join(__dirname, 'coulson.jpg'), // absolute path (not balloons) sound: true, // Only Notification Center or Windows Toasters wait: true // wait with callback until user action is taken on notification }, function (err, response) { // response is response from notification }); notifier.on('click', function (notifierObject, options) { // Happens if `wait: true` and user clicks notification }); notifier.on('timeout', function (notifierObject, options) { // Happens if `wait: true` and notification closes }); 

通知是这样的:

在这里输入图像描述

正如你可以看到一个terminal图标在名称之前。

你能帮我怎么删除那个图标吗?

这是node-notifier的已知问题。

从问题#71 :

mikaelbr :

不,恐怕通知是如何工作的,因为它是启动消息的terminal。 避免这种情况的唯一方法是使用自定义terminal通知符,其中terminal图标被交换为您自己的。 这不是一个大任务,您可以轻松地为通知中心记者设置customPath 。

kurisubrooks :

发生这种情况是因为OS X中的通知工作。 通知将显示引用的应用程序图标,因为我们正在使用terminal通知程序推送通知,所以我们有terminal通知程序的图标。

要解决这个问题,你需要用你自己的app.icns编译terminal通知器。 下载源代码,在Xcode中用你自己的代码更改AppIcon包,重新编译terminal通知程序,并将其popup到节点通告程序中。 ( /node-notifier/vendor/terminal-notifier.app

现在,在节点通告程序中有自己的terminal通知程序,从OS X通知中心代码中删除所有图标引用,并运行通知,就好像它没有图标一样。 如果通知中显示旧应用图标,则需要清除图标caching。 (Google如何做到这一点)

mikaelb另一个有价值的评论:

这是正确的。 但请记住,node-notifier使用terminal-notifier( github.com/mikaelbr/terminal-notifier )的分支来添加等待通知完成的选项,因此应该使用它来添加自己的图标。 一个简单的方法是从供应商文件夹复制/粘贴,并使用customPath指向您自己的供应商。

我尝试了@Aleksandr M的步骤,但似乎并没有为我工作。 也许我不太了解这些步骤。 这是如何为我工作。

我克隆了https://github.com/mikaelbr/terminal-notifier 。 然后用xcode打开项目并删除了Terminal.icns文件,并将其replace为我的自定义图标Myicon.icns

然后通过将密钥icon file设置为Myicon来编辑terminal-notifier/Terminal Notifier/Terminal Notifier-Info.plist

做完这个之后,简单地构build项目就行不通了。 我不得不改变build versionbuild identifier值(任何新的值), 看看这个 。

之后,我用xcode构build了项目,然后复制了构build.app文件(可以通过点击xcode Products > right click the file > show in finder项目的Products目录, Products > right click the file > show in finder )find我的电子项目

例如你的最终path可能是这样的。 electron-project/vendor/terminal-notifier.app

然后我将customPath设置为@Aleksandr Mbuild议。

这是我的样子

var notifier = new NotificationCenter({ customPath: 'vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier' });

然后,它的工作! 🙂