Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 132033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:11:56+00:00 2026-05-11T06:11:56+00:00

I’d like to write a Python script for Amarok in Linux to automatically copy

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:11:57+00:00Added an answer on May 11, 2026 at 6:11 am

    Update: As said in comments, Hal is not supported in recent distributions, the standard now is udev, Here is a small example that makes use of glib loop and udev, I keep the Hal version for historical reasons.

    This is basically the example in the pyudev documentation, adapted to work with older versions, and with the glib loop, notice that the filter should be customized for your specific needing:

    import glib  from pyudev import Context, Monitor  try:     from pyudev.glib import MonitorObserver      def device_event(observer, device):         print 'event {0} on device {1}'.format(device.action, device) except:     from pyudev.glib import GUDevMonitorObserver as MonitorObserver      def device_event(observer, action, device):         print 'event {0} on device {1}'.format(action, device)  context = Context() monitor = Monitor.from_netlink(context)  monitor.filter_by(subsystem='usb') observer = MonitorObserver(monitor)  observer.connect('device-event', device_event) monitor.start()  glib.MainLoop().run() 

    Old version with Hal and d-bus:

    You can use D-Bus bindings and listen to DeviceAdded and DeviceRemoved signals. You will have to check the capabilities of the Added device in order to select the storage devices only.

    Here is a small example, you can remove the comments and try it.

    import dbus import gobject  class DeviceAddedListener:     def __init__(self): 

    You need to connect to Hal Manager using the System Bus.

            self.bus = dbus.SystemBus()         self.hal_manager_obj = self.bus.get_object(                                               'org.freedesktop.Hal',                                                '/org/freedesktop/Hal/Manager')         self.hal_manager = dbus.Interface(self.hal_manager_obj,                                           'org.freedesktop.Hal.Manager') 

    And you need to connect a listener to the signals you are interested on, in this case DeviceAdded.

            self.hal_manager.connect_to_signal('DeviceAdded', self._filter) 

    I’m using a filter based on capabilities. It will accept any volume and will call do_something with if, you can read Hal documentation to find the more suitable queries for your needs, or more information about the properties of the Hal devices.

        def _filter(self, udi):         device_obj = self.bus.get_object ('org.freedesktop.Hal', udi)         device = dbus.Interface(device_obj, 'org.freedesktop.Hal.Device')          if device.QueryCapability('volume'):             return self.do_something(device) 

    Example function that shows some information about the volume:

         def do_something(self, volume):         device_file = volume.GetProperty('block.device')         label = volume.GetProperty('volume.label')         fstype = volume.GetProperty('volume.fstype')         mounted = volume.GetProperty('volume.is_mounted')         mount_point = volume.GetProperty('volume.mount_point')         try:             size = volume.GetProperty('volume.size')         except:             size = 0          print 'New storage device detectec:'         print '  device_file: %s' % device_file         print '  label: %s' % label         print '  fstype: %s' % fstype         if mounted:             print '  mount_point: %s' % mount_point         else:             print '  not mounted'         print '  size: %s (%.2fGB)' % (size, float(size) / 1024**3)  if __name__ == '__main__':     from dbus.mainloop.glib import DBusGMainLoop     DBusGMainLoop(set_as_default=True)     loop = gobject.MainLoop()     DeviceAddedListener()     loop.run() 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 141k
  • Answers 141k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you have a list of employees and a list… May 12, 2026 at 8:03 am
  • Editorial Team
    Editorial Team added an answer The copy/cut/paste UI is given for free with any of… May 12, 2026 at 8:03 am
  • Editorial Team
    Editorial Team added an answer Unfortunatly I'm not aware of any other way (I also… May 12, 2026 at 8:03 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.