Yenya's World

Wed, 21 Feb 2007

Device Event Handler

An useless but nice hack of the day: I have explored the udev rules a bit further - with udev, it is possible even to run a script when the device is created. I wrote two simple scripts - one at home, where it loads images from my camera after I plug the camera in, and stores them into my image repository. The other at work - around 6:30pm, I download the main daily news from the Czech radio station Radiožurnál, encode it to OGG/Vorbis, and when my Palm is plugged in, the script started by udev copies the audio file to the Palm. The rule itself is pretty simple:

$ cat /etc/udev/rules.d/60-palm-news.rules
KERNEL=="sd*1", SYSFS{serial}=="50xxxxxxxxxxxxxxxxxxxx39", \
    SYSFS{product}=="palmOne Handheld", \
    SYSFS{manufacturer}=="palmOne, Inc.", \

The tricky part was to not interchange double "==" with the single "=" by accident, and using the "KERNEL" parameter (otherwise, the script would be run for every virtual device along the path (USB device, virtual SCSI controller of the mass storage device, the whole USB disk, and finally every partition on that disk).

Another tricky part is to use device nodes from /dev/disk/by-uuid in the mount(8) command, so that the device path remains the same no matter which USB port I plug my PDA into, or what other mass storage devices are currently plugged in.

As an user-friendly bonus, the "news-to-palm" script uses notify-send to send a completion message over D-bus to inform me that I can unplug the PDA.

UPDATE 2007/02/22: More details
I forgot to mention some important tips:

Section: /computers/desktops (RSS feed) | Permanent link | 2 writebacks

2 replies for this story:

oozy wrote: d-bus

Nice. I would like to see the news-to-palm script. Especially I'm interested in notification via d-bus. Can you provide a link please? :)

Yenya wrote: Re: d-bus

The notification is simple: su kas -c 'DISPLAY=:0 notify-send "Zpravy" "Kopiruji zpravy do Palma..." -- however, this relies on knowing that I am user "kas" and I am always logged in at :0 display. I think it should be possible to send notification over the system d-bus as well (as opposed to the session d-bus), but I currently don't know how to do it.

Reply to this story:

URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Key image: key image (valid for an hour only)
Key value: (to verify you are not a bot)


Yenya's World: Linux and beyond - Yenya's blog.


RSS feed

Jan "Yenya" Kasprzak

The main page of this blog



Blog roll:

alphabetically :-)