[Gllug] Dbus/Hal - doing useful things
Nix
nix at esperi.org.uk
Thu Oct 20 12:20:37 UTC 2005
On Thu, 20 Oct 2005, Tethys mused:
> Huw Lynes writes:
>
>>What I want to do is run a program when a particular device gets
>>attached. I could write a python app (the dbus python bindings don't
>>look that hard) and get Gnome to autostart it. Then it can listen to
>>Dbus and do it's stuff when it sees the device get attached.
>
> No need to look for dbus events yourself. Hotplug's usb agent already
> runs whenever a new USB device is attached. You could almost certainly
> convince it to run your script for you when your device is attached.
>
> It may be a simple as just plonking it in /etc/hotplug/usb along with
> a suitable usermap file. It's one of those things I've been meaning to
> look into for a while, but never got past a cursory glance at it...
And if you're had enough of hotplug (the hotplug scripts are terribly
obsolete), then sticking something like this udev rule in somewhere
under /etc/udev/rules.d will do the trick (this one is for my
MP3 player):
KERNEL=="sd*1", SYSFS{product}=="ARCHOS*", SYMLINK="archos"
KERNEL=="sd*1", SYSFS{product}=="ARCHOS*", ACTION=="add", PROGRAM="/sbin/mount %p"
This is really a gross abuse of PROGRAM, but it works. :)
(It is *not* safe to add a umount on remove, because the remove event
happens *after* the device is unplugged, which is too late to flush
buffers and things. It would be safe if the disk were mounted read-only,
though.)
To get the various keys you can use, try, e.g.,
udevinfo -p /sys/block/sda -a
and have a look at the udev manpage.
udev really, really, *seriously* rocks.
--
`"Gun-wielding recluse gunned down by local police" isn't the epitaph
I want. I am hoping for "Witnesses reported the sound up to two hundred
kilometers away" or "Last body part finally located".' --- James Nicoll
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list