Create icons on rox desktop of automounted media by ivman

This post has been updated! Please read this one too: rox icons + ivman continued

Whenever some people looked at my desktop they always mocked me for some of the features that were missing from fluxbox + rox and were present in the big WM like Gnome or KDE. One of those “neat” features is the automounting of cd-rom/dvd disks or usb flash drives and the appearance of an icon of those on the desktop.
I stared reading the Gentoo Wiki and the Gentoo forums on the subject. I came up with these 2 pages:
HOWTO_ivman on and automount add icons desktop dynamically ivman+rox. Following the Gentoo wiki guide I was able to easily install ivman and hal and configure the local users to be able to mount unknown devices automatically. So the first part was really easy. Then it was time to make rox appear a new icon on the desktop every time a new media is found.
I first tried to follow the gentoo forum post, to make rox appear icons on the desktop with every new media but it didn’t quite satisfy me. I faced various problems with the scripts posted there mostly about media without volume.label and about cds/dvds that got ejected but their icon was never removed from the desktop. My search for a more elegant solution than trying to fix those scripts continued and I ran into this page on the RoxWiki: Hints And Tips/HAL.
That post involved some patching of hal, but I wasn’t willing to do that. Instead I tried to make the scripts posted there without patching. And indeed I succeded.
Follow these steps to “reproduce”:
1) create a shell script named rox.panelput with the following contents: THERE IS A NEWER VERSION OF THIS SCRIPT —> rox icons + ivman continued

#!/bin/sh
### Change "Top" below to the panel you want your devices on...
rox --RPC << EOF
<?xml version="1.0"?>
<env :Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
</env><env :Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
<pinboard$1>
<path>$2</path>
<x>20</x>
<y>50</y>
<label>$2</label>
</pinboard>
</env>
EOF

2) Become root and make it executable and move it to /usr/bin/:
chmox +x rox.panelput ; mv rox.panelput /usr/bin

3) Edit .ivman/IvmConfigProperties.xml and paste the following inside there:

<ivm:Match name="ivm.mountable" value="true">
<ivm:Property name="hal.volume.is_mounted">
<ivm:Action value="true" exec='rox.panelput Add "$hal.volume.mount_point$"' />
<ivm:Action value="false" exec='rox.panelput Remove "$hal.volume.mount_point$"' />
</ivm:Property>
</ivm:Match>

4) As root again rename your /usr/bin/eject to /usr/bin/eject.old and create a new shell script named eject
mv /usr/bin/eject /usr/bin/eject.old

#!/bin/bash
rox.panelput Remove $1; eject.old $1

This is needed because we did not patch hal. What the patch would do to hal is make it not forget the “volume.mount_point” after a device removal. That would cause ivman to succeed when it would try to rox.panelput Remove “$hal.volume.mount_point$”. That’s not the case without the patch though. After a device is removed from the system hal does not know anymore which was the $hal.volume.mount_point$ so the icon never gets removed from the rox desktop. But since I use as label the path of the device, I can remove the device and icon together with that custom script. It a really simple hack, not an ellegant one, but it works.

5) restart ivman as user and watch rox add icons to your desktop.

It should look like this:

Pros:
1) Fast and easy way to have icons of media on your rox desktop
Cons:
1) Does not diplay the volume.label of a media but just the mount point
2) Does not automatically position new icons one below the other. If you insert 2 media, the last icon will fall on top of the previous one.

Improvements for the future:
1) Automatic placement of the icons one below the other
In oder to do so I will have to count how many icons have already been created on the desktop and store them in a temp file.

2) Icons should have volume.label as their label and not the mount point
It’s easy to do it for media that do have a label, but what about the ones that don’t ? eg my dicicam Olympus C-70z does not have a volume label. Maybe an “Unknown Device” would be the solution there…but then I will lose the functionality of my custom “eject” script…I’ll have to look into it.

3) Make icons be different according to media type (usb flash/cdrom/dvd/etc)

In a few words…I have to make it behave like the user from the gentoo forum wanted his scripts to behave…