node-notifier icon indicating copy to clipboard operation
node-notifier copied to clipboard

How to remove notification?

Open neojski opened this issue 10 years ago • 20 comments

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.

neojski avatar Jun 27 '15 20:06 neojski

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.

mikaelbr avatar Jun 27 '15 21:06 mikaelbr

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

sayanee avatar Jun 28 '15 05:06 sayanee

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.

neojski avatar Jun 28 '15 13:06 neojski

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.

jariz avatar Jul 23 '15 08:07 jariz

Has anyone solved this problem ?

allenm avatar Dec 05 '16 11:12 allenm

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 avatar Dec 05 '16 12:12 mikaelbr

@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 .

allenm avatar Dec 05 '16 12:12 allenm

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.

mikaelbr avatar Dec 05 '16 12:12 mikaelbr

Yes, I have print the arguments. The arguments are right .

allenm avatar Dec 05 '16 12:12 allenm

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?

mikaelbr avatar Dec 05 '16 12:12 mikaelbr

Yes , have tried . Direct run the terminal-notifier in the vendor-folder is ok too.

allenm avatar Dec 05 '16 12:12 allenm

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.

mikaelbr avatar Dec 05 '16 12:12 mikaelbr

Tried set uid and gid , not work yet. And I find when pass the parms ['-remove', '"ALL"'], the ternimal-notifier will not quit.

allenm avatar Dec 05 '16 13:12 allenm

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?

mikaelbr avatar Dec 05 '16 13:12 mikaelbr

use cp.exec('./terminal-notifier -remove ALL') , the result is same .

allenm avatar Dec 05 '16 13:12 allenm

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);
});

lihang1870719 avatar Apr 13 '17 04:04 lihang1870719

Hi guys! Did anybody find some solution or workaround for Mac?

clusterberries avatar Dec 29 '17 09:12 clusterberries

someone could do this? it doesn't work when you package the app

BluFenix00 avatar May 07 '19 14:05 BluFenix00

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 avatar May 01 '20 22:05 burasuk

@burasuk I tried your solution but, what it does is re-display the notification when it emits the timeout

tboulis avatar Oct 26 '22 11:10 tboulis