简体   繁体   English

从Windows 10通知中触发python中的脚本

[英]Trigger a script in python from a Windows 10 Notification

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. 每当我在Windows 10上收到通知时,我都希望执行Python脚本。然后,基于该通知,我将能够执行不同的任务。 For example: if I get a notification from Slack, I could blink a led on an Arduino connected to the PC. 例如:如果我从Slack收到通知,则可以使连接到PC的Arduino上的LED闪烁。

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? 我可以看到,如果我用C#编写应用程序,则Microsoft在其UWP api中有一个UserNotificationListener类,但是我可以从Python或Powershell中访问相同的功能吗?

but can I access the same functionality from Python or from Powershell 但是我可以从Python或Powershell中访问相同的功能吗

As far as I know Python and UWP technology cannot call any API between themselves. 据我所知,Python和UWP技术无法在它们之间调用任何API。 So I don't think this is possible. 所以我认为这是不可能的。

I would like to execute a Python script whenever I receive a notification on Windows 10 我想在Windows 10上收到通知时执行Python脚本

However this is possible for us to do from UWP itself. 但是,我们可以通过UWP本身来做到这一点。

Please have a look at this thread: Launch powershell script from UWP app with FullTrustProcessLauncher class . 请看一下这个线程: 使用FullTrustProcessLauncher类从UWP应用启动powershell脚本 As the title of that thread mentioned, the desktopbridge technology enables full trust access for normal win32 apps to be called from UWP technology. 正如该线程的标题所述,desktopbridge技术使普通的Win32应用程序能够通过UWP技术调用完全信任访问。 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. 因此,当您创建自己的应用程序以监听通知时,如果收到新的通知,则可以在事件中添加一个调用,然后执行您的powershell脚本。 The calling process is handled by your win32 exe. 调用过程由您的win32 exe处理。 I think this does make sense for your requirement. 我认为这确实符合您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM