Alex Rivera | Logout

How can I listen for 'usb device inserted' events in Linux, in Python?

Asked 2009-01-22T14:09:59.667
39

I'd like to write a Python script for Amarok in Linux to automatically copy the stackoverflow podcast to my player. When I plug in the player, it would mount the drive, copy any pending podcasts, and eject the player. How can I listen for the "plugged in" event? I have looked through hald but couldn't find a good example.

Edit
Report

1 Answer

4

I think D-Bus would work as Chris mentioned, but if you're using KDE4, you might use the Solid framework in a manner similar to the KDE4 "New Device Notifier" applet.

The C++ source for that applet is here, which shows how to use Solid to detect new devices. Use PyKDE4 for Python bindings to these libraries, as shown here.

answered 2009-01-22T15:15:46.133

Your Answer