Page 1 of 1
how to check if toast notification exists
Posted: 19 Apr 2024, 16:03
by redrum
I tried the following, but it does not see the toast notification, even though WindowSpy does, which is where I got the title and ahk_exe.
Code: Select all
SetTitleMatchMode 2
if WinExist("New notification ahk_exe ShellExperienceHost.exe")
{ do something }
else MsgBox("window not found")
Also tried using the title by itself, and that's also not found.
Re: how to check if toast notification exists
Posted: 19 Apr 2024, 16:17
by mikeyww
I did not test this, but
WinExist does not wait for a window to appear. Instead, this is an instantaneous check. To wait for a window, use
WinWait.
If SetTitleMatchMode is not used, the default match mode is 2.
Assessing WinExist does not require any
If statements. Instead, the value returned by WinExist can be displayed.
Re: how to check if toast notification exists
Posted: 19 Apr 2024, 16:29
by redrum
mikeyww wrote: ↑19 Apr 2024, 16:17
I did not test this, but
WinExist does not wait for a window to appear. Instead, this is an instantaneous check. To wait for a window, use
WinWait.
In this particular use case, the window, or rather, toast notification, does already exist.
mikeyww wrote: ↑19 Apr 2024, 16:17
Assessing WinExist does not require any
If statements. Instead, the value returned by WinExist can be displayed.
Value is zero if I use
Code: Select all
MsgBox(WinExist("New notification ahk_exe ShellExperienceHost.exe"))
Re: how to check if toast notification exists
Posted: 19 Apr 2024, 17:50
by mikeyww
Code: Select all
#Requires AutoHotkey v2.0
If !Instr(A_AhkPath, 'UIA') && !((cLine := DllCall('GetCommandLine', 'str')) ~= ' /restart(?!\S)')
If FileExist(ahk := A_ProgramFiles '\AutoHotkey\v2\AutoHotkey64_UIA.exe') {
Try Run ahk ' /restart ' RegExReplace(cLine, '.+\.exe.*? ')
ExitApp
} Else MsgBox 'File not found.`n`n' ahk, 'Error', 48
TrayTip 'Multiline`nText', 'My Title', 'Iconi Mute'
WinWait 'New notification ahk_exe ShellExperienceHost.exe'
MsgBox