June 15, 2020

AutoHotkey: TrayTipAutoHide

There is a nice function in AutoHotkey to display system tray notifications called TrayTip.
I present here an adaption to display the notification and auto-hide after a customizable time.
(The 3rd input parameter 'Time' in the active TrayTip function has no effect on Windows Vista and later.)

Code

TrayTipAutoHide(Title,Text,Time:=2000,Options:=0){
TrayTip %Title%, %Text%,,Options
Sleep %Time%   ; Let it display for %time% in ms
HideTrayTip()
}

HideTrayTip() {
TrayTip  ; Attempt to hide it the normal way.
if SubStr(A_OSVersion,1,3) = "10." {
    Menu Tray, NoIcon
    Sleep 200  ; It may be necessary to adjust this sleep.
    Menu Tray, Icon
    }
}

You can also download this function from my GitHub AHK Repository here.

Usage

The function will simply pass the first 2 arguments and last argument for the options to the TrayTip function.
Last 2 arguments are optional.
Default Time (in ms) is set to 2s.
Refer to TrayTip for possible options.

See also

https://jacks-autohotkey-blog.com/2020/06/15/alternative-autohotkey-notice-commands


No comments:

Post a Comment