Dismiss Notifications with Keyboard


Is there a way to dismiss “sticky” notifications (that appear top right of the widow, red for “Error” for example) using the keyboard? I’ve had a dig but can’t find a command. Thanks!


You can create a command that does this. Put this in your ~/.atom/init.coffee:

atom.commands.add 'atom-workspace', 'custom-commands:dismiss-notifications', ->
  atom.notifications.getNotifications().forEach (notification) ->

Then you can create a keybinding for the command. Put this in ~/.atom/keymap.cson

  'ctrl-shift-d': 'custom-commands:dismiss-notifications'

Replace the key combo with whatever you want.


I wonder if I can do it with the escape key, which is the obvious key.


Works for me if I just replace ctrl-shift-d with escape

EDIT - although it does break most uses of escape like closing the find/keybinding resolver panels etc.


Thanks, @olmokramer - that works great!

I’ve only tried the ctrl+shift+d option though I agree with @mark_hahn ‘escape’ would be the obvious option, but perhaps there is no way (yet) to restrict a keybinding to a context? i.e if notification is present use it to close it, otherwise move on to the next likely use. I don’t have the chops to work out the answer.


You can restrict a keybinding to a context. Keybindings consist of three components:

  '<keybinding>': '<command>'

The context is a CSS selector - atom-workspace in the example above - so you can’t perform checks like you describe at the context definition (or the command would only trigger if a notification was focused, requiring you to use the mouse anyway). You can, however, perform such checks in the command code.

This improved version dismisses all notifications that haven’t been dismissed yet. Then it checks if it has dismissed more than 0 notifications, if not it dispatches the core:cancel command on the atom-workspace. This should cover most cases where things break.

atom.commands.add 'atom-workspace', 'custom-commands:dismiss-notifications', (e) ->
  dismissedCounter = 0
  atom.notifications.getNotifications().forEach (notification) ->
    unless notification.dismissed
  if dismissedCounter is 0
    atom.commands.dispatch e.currentTarget, 'core:cancel'

And in keymap.cson

  'escape': 'custom-commands:dismiss-notifications'


That is how my various popups work. I put a listener for any keypress from the workspace and check the value (e.which) for escape (27). If I see an escape I close my popup and then stop propagation of the event.

This has worked so far. First escape closes my popup and second closes find/replace.

Maybe I can do the equivalent for the notification popups. I might have to do it in a package.


Our messages crossed. I’ll try your solution.


How does Esc close Find/Replace? Perhaps the same command could dismiss the error popup, too? Do we really need to be able to dismiss just the error popup, keeping Find/Replace open? After all, Cmd-Shift-F brings Find/Replace back.

Esc FTW!


Of course! Haha I feel silly now.

Just add to init.coffee:

atom.commands.add 'atom-workspace', 'core:cancel', ->
  atom.notifications.getNotifications().forEach (notification) ->


Is there a reason not to make this a core behavior? To me, it’s a no-brainer that this is the right behavior. But perhaps I’m overlooking something.


As long as it doesn’t cause issues with other stuff, I’d think that this would be a great pull request for the atom/notifications repository.


I was thinking core’s NotificationManager


Sure … that works too :laughing:


Silly? Trust me, my ignorance is far far greater!


Thanks for the replies. I do think it would be good core behavior.
That said the solution above works great for me (and I learned something which is cool), so thanks!


PR submitted:


If you would like to change the location to the bottom right you can put this code in your styles.less file:

atom-notifications {
  top: auto;