Dismissing system tray notifications

Get help with using AutoHotkey and its commands and hotkeys
AHKxx
Posts: 54
Joined: 26 Feb 2014, 01:37

Dismissing system tray notifications

01 May 2015, 03:18

Can an AHK script dismiss a system tray notification, instantly, without it fading?

There's a TrayTip function where if all params are omitted "any TrayTip window currently displayed will be removed." But that's not working as I would expect it to.

I'd like to be able to swat notifications dead in one go, rather than having to click the little x, in the process prolonging the display as I pass over it.

Thanks.
User avatar
TheDewd
Posts: 1334
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Dismissing system tray notifications

01 May 2015, 16:18

Are you referring to TrayTip? Just run it with no parameters. See example code below:

Code: Select all

#SingleInstance, Force ; ALLOWS ONLY ONE RUNNING INSTANCE OF SCRIPT

; SET TRAYTIP
TrayTip, Test, Test
Return

; PRESS F1 TO DISABLE TRAYTIP.
F1::
	TrayTip
Return
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
lexikos
Posts: 6591
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Dismissing system tray notifications

01 May 2015, 21:05

@TheDewd: Read the second paragraph, where AHKxx said that's not working.

TrayTip is only for notifications raised by the script.

I normally right click notifications to dismiss them, because it's far easier than clicking the [x]. This should work with any notifications that don't override right-click:

Code: Select all

ControlClick,, ahk_class tooltips_class32,, R
WinClose also appears to work, but breaks tray tips until explorer.exe is restarted.

WinHide partially works; it leaves a shadow window behind.
AHKxx
Posts: 54
Joined: 26 Feb 2014, 01:37

Re: Dismissing system tray notifications

01 May 2015, 21:55

Thanks for the repies.

@lexikos: Your line of code was just what I'm looking for.

I wasn't aware that right clicking or Ctrl clicking a notification would close it.

Is there any downside in implementing it as follows, using the Escape key as the hot key, and including {Esc} itself as part of the script, so that Escape always gets sent as normal, and the CtrolClick will either kill any notification showing, or do nothing at all? Or am I being too clever here?

Code: Select all

Esc:: 
Send {Esc}
ControlClick,, ahk_class tooltips_class32,, R
return
lexikos
Posts: 6591
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Dismissing system tray notifications

01 May 2015, 21:59

Yes, there are downsides:
  • Programs will not be able to detect when you are holding Escape.
  • Sending a key is not as reliable as physically pressing it.
Just use ~Esc:: instead.

Code: Select all

~Esc:: 
ControlClick,, ahk_class tooltips_class32,, R
return
AHKxx
Posts: 54
Joined: 26 Feb 2014, 01:37

Re: Dismissing system tray notifications

01 May 2015, 22:12

Amazing. AHK is simply amazing. (Never used a tilde hotkey before.)

Thanks so much for the replies and the insight.

Return to “Ask For Help”

Who is online

Users browsing this forum: anaxio, eL Tux, Google [Bot], MannyKSoSo, Odlanir, swagfag and 219 guests