Page 1 of 1

Dismissing system tray notifications

Posted: 01 May 2015, 03:18
by AHKxx
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.

Re: Dismissing system tray notifications

Posted: 01 May 2015, 16:18
by TheDewd
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

Re: Dismissing system tray notifications

Posted: 01 May 2015, 21:05
by lexikos
@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.

Re: Dismissing system tray notifications

Posted: 01 May 2015, 21:55
by AHKxx
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

Re: Dismissing system tray notifications

Posted: 01 May 2015, 21:59
by lexikos
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

Re: Dismissing system tray notifications

Posted: 01 May 2015, 22:12
by AHKxx
Amazing. AHK is simply amazing. (Never used a tilde hotkey before.)

Thanks so much for the replies and the insight.