I want to trigger a python script when a USB device which is identified by product id and vendor id is attached to the system. I'm working on windows 10 right now. but a cross platform solution is always welcomed.
Asked
Active
Viewed 509 times
0
-
Have you looked into `pywinusb` package? – Raguel Dec 15 '20 at 07:45
-
@Raguel thanks seems like `pywinusb` has the potential – pouya Dec 15 '20 at 08:26
1 Answers
0
Wanted to leave this as comment, but I'm not able to do that yet.
According to this question, this, this, this one it seems that you should be able to do what you want, have you tried any of these solutions?
In other words you should be able to:
- Monitor (1,3) if any new device was connected by pooling
- Query the device for its infos and see if it is of your interest (on windows WMI seems the best option, but you can fallback to issue a powershell command for a quick and dirty PoC)
- Perform the action if the condition are met

emmunaf
- 426
- 2
- 9
-
Thanks for providing an answer. Actually using `subprocess` to run a command is a hack not a solution (at least for me) and cause there is no dominating cross platform package in python (to my knowledge) such a question is asked every few years actually in Linux `pyudev` is a great solution – pouya Dec 15 '20 at 08:21
-
Nice, it seems that I can add comment to my own answer. I agree with you about the subprocess but sometimes this can be better than nothing. Have you also tried with [pywin32](https://stackoverflow.com/a/8110666/11265715)? – emmunaf Dec 15 '20 at 08:29
-
1Yes, it 's on my radar but I think `pywinusb` suggested by @Raguel (%100 python) is better suited for this simple task – pouya Dec 15 '20 at 08:37