node-notifier
node-notifier copied to clipboard
How to remove notification?
Sometimes I want to remove user's notification programatically because of some user's action. Is this possible? If that's os specific, I'm mostly interested in linux for now.
I haven't found a way to do this on Linux (with notify-send). You could do this with Notification Center on a Mac though, but I figure that doesn't help.
I believe it's this code with terminal-notifier:
notifier.notify({
'remove': 'ALL' // to remove all group ID
});
but it's not working for me either
I guess that what @sayanee was supposed to work. There's even a test for it. It doesn't work for me either so you might consider reviewing that test @mikaelbr.
Can also confirm that it does not work. Very strange, When running the exact same command that node-notifier produces from my shell, it works perfectly, but once node-notifier runs the command itself, things start getting weird.
Has anyone solved this problem ?
As far as I could find, there wasn't a way to do this in terminal-notifier. There is an API for it, and node-notifier supports that API, but it doesn't seem to work.
@mikaelbr just use terminal-notifier -remove ALL is OK. But node-notifier not work .
I think when run terminal-notifier in child process ,something wrong .
Could you verify that the correct arguments are used when calling node-notifier? You can print the arguments by editing the utils-file where child processes are spawned.
Yes, I have print the arguments. The arguments are right .
Interesting. There's either an issue with access, or something else going on here. Are you trying to run the terminal-notifier in the vendor-folder so you know it's the same one? Have you tested out the maste branch of node-notifier?
Yes , have tried . Direct run the terminal-notifier in the vendor-folder is ok too.
Hm. What seems to remain then is either the way it is spawned (through execFile) or access level. Could try setting the uid or gid options to execFile for instance.
Tried set uid and gid , not work yet. And I find when pass the parms ['-remove', '"ALL"'], the ternimal-notifier will not quit.
Would be great to know if this is a problem with the actual execution, or something else we're missing. For instance, if one takes a working command and copies it to a simple node script like something as cp.exec('./terminal-notifier -remove ALL') and try that, will it have the same issue?
use cp.exec('./terminal-notifier -remove ALL') , the result is same .
use like this, the result is nomarl
cp.execFile('*/terminal-notifier', ['-message', '111'], function(error, stdout, stderr){
if(error){
throw error;
}
console.log(stdout);
});
but when I use the remove, I get the same problem
cp.execFile('*/terminal-notifier', ['-remove', 'ALL'], function(error, stdout, stderr){
if(error){
throw error;
}
console.log(stdout);
});
Hi guys! Did anybody find some solution or workaround for Mac?
someone could do this? it doesn't work when you package the app
when i want to remove existing notification on timeout, dismissed:
const id = 123; // <= this is crutial (some random number)
const notifyOpt = {
message: 'Message',
actions: ['OK', 'Cancel'],
id: id,
};
notifier.notify(notifyOpt);
// on timeout
notifier.on('timeout', () => {
const extendProps = Object.assign(notifyOpt, {
remove: id
})
notifier.notify(extendProps ); // <= this overrides previously notification and remove it immediately
});
going further, if you want to show notifications indefinitely(with remove previous notification) until the user clicks message:
const id = 123; // <= this is crutial (some random number)
const notifyOpt = {
message: 'Message',
actions: ['OK', 'Cancel'],
id: id,
};
notifier.notify(notifyOpt);
// on timeout
notifier.on('timeout', () => {
notifier.notify(notifyOpt );
});
@burasuk I tried your solution but, what it does is re-display the notification when it emits the timeout