I'm trying to create a script where it is able to listen to windows notifications and found this website "How can i listen to windows 10 notification" I tried to use the guide from that website but unfortunately received an "Element not found" error. I was hoping if someone could explain to me how this error occur and the methods to fix it.
Below is the code that I used. (mostly from the website stated above)
from winrt.windows.ui.notifications.management import UserNotificationListener, UserNotificationListenerAccessStatus
from winrt.windows.foundation.metadata import ApiInformation
if not ApiInformation.is_type_present("Windows.UI.Notifications.Management.UserNotificationListener"):
print("UserNotificationListener is not supported on this device.")
exit()
listener = UserNotificationListener.get_current()
accessStatus = listener.get_access_status()
if accessStatus != UserNotificationListenerAccessStatus.ALLOWED:
print("Access to UserNotificationListener is not allowed.")
exit()
def handler(listener, event):
notification = listener.get_notification(event.user_notification_id)
# get some app info if available
if hasattr(notification, "app_info"):
print("App Name: ", notification.app_info.display_info.display_name)
listener.add_notification_changed(handler)
Error I received:
listener.add_notification_changed(handler)
RuntimeError: Element not found.