1

I would like to execute a Python script whenever I receive a notification on Windows 10. Then, based on the notification, I would be able to execute different tasks. For example: if I get a notification from Slack, I could blink a led on an Arduino connected to the PC.

I see that Microsoft has a UserNotificationListener class as part of its UWP api in case I write an app in C#, but can I access the same functionality from Python or from Powershell?

1
  • I believe my question is clear. I don't know if I have to use the mentioned class, or if there is another way to achieve what I want, and that's why I described what's my goal. And yes, I did some research, which got to me the the UserNotificationListener. I don't need anybody to do all the work for me - I asked if there's a certain functionality from a certain environment, pretty straightforward. Any suggestion how that could be asked instead? Commented Feb 16, 2018 at 9:26

2 Answers 2

1

but can I access the same functionality from Python or from Powershell

As far as I know Python and UWP technology cannot call any API between themselves. So I don't think this is possible.

I would like to execute a Python script whenever I receive a notification on Windows 10

However this is possible for us to do from UWP itself.

Please have a look at this thread:Launch powershell script from UWP app with FullTrustProcessLauncher class. As the title of that thread mentioned, the desktopbridge technology enables full trust access for normal win32 apps to be called from UWP technology. So when you create your own app which listens to the notification, if a new notification is received, you can add a call in your event which will then execute your powershell script. The calling process is handled by your win32 exe. I think this does make sense for your requirement.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot @Barry Wang - MSFT
0
from plyer import notification

def on_notification(title, message):
    if title == "Trigger Script":
        print("Script triggered from notification")

def main():
    while True:
        notification.notify(
            title="Trigger Script",
            message="Click this notification to run a script.",
            app_name="My Python App"
        )

if __name__ == "__main__":
    main()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.