You are not logged in.

#1 2010-06-11 06:40:26

moere
Member
Registered: 2010-02-14
Posts: 29

pcmanfm, udev for usb device mounting, automatically show up

Hi there.

I am using lxde and pcmanfm.

On one of my system I still have hal running
and the pcmanfm seems to use hal to automount usb devices.
So when I plug in a device it shows up in pcmanfm (in the left "locations" bar).


On another system I use pcmanfm without hal,
instead I use udev.
I read in the wiki that pcmanfm2 uses GVFS for mounting stuff.


But  I would like to stick to udev for that.

Now I am looking for a way to automatically show the usb device in
the location bar of pcmanfm when the udev rule mounts it.

Has somebody done this before? Solved it in any way?


My idea wold be to automatically create a pcmanfm bookmark on mounting
and delete it again on unmounting.

I found out that pcmanfm uses ".gtk-bookmarks" for its bookmarks.


So is there someone out there who would like to solve this challange for me? wink

Editing this code: ( I took it  from http://wiki.archlinux.org/index.php/Ude … n-mounting)

KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"

# Get label
PROGRAM=="/sbin/blkid -o value -s LABEL %N", ENV{dir_name}="%c"
# use basename to correctly handle labels such as ../mnt/foo
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"
ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"

ACTION=="add", ENV{dir_name}!="", RUN+="/bin/su tomk -c '/usr/bin/pmount %N %E{dir_name}'"
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/su tomk -c '/usr/bin/pumount /media/%E{dir_name}'"
LABEL="media_by_label_auto_mount_end"

So that it puts the bookmark in the .gtk-bookmarks file and removes it automatically?

I am not that good at bash scripting.

Okey, maybe nobody wants to do the work for me.. I can understand that.

But do you guys think it would work??

Last edited by moere (2010-06-11 06:40:50)

Offline

#2 2010-08-20 16:16:59

Damstre
Member
Registered: 2010-08-20
Posts: 1

Re: pcmanfm, udev for usb device mounting, automatically show up

Hi,

I have been trying to do the same thing and I came up with a solution.
I wrote a little script that write an entry into .gtk-bookmarks when pluging a device and removing this entry when the device is removed, and then modify the rule so that it runs.

Here it is

#!/bin/bash
if [ "$ACTION" = "add" ]; then
echo file:///media/$1 $1 >> yourhomedirectory/.gtk-bookmarks
elif [ "$ACTION" = "remove" ]; then
sed -i -e '/'$1'/d' yourhomedirectory/.gtk-bookmarks
fi

Just replace yourhomedirectory with what is convenient. I'd like to put $HOME here but it doesn't work since I am not the one running the script...

you must then modify your udev rule adding this after each action to make the script run.

RUN+="pathtothescript %E{dir_name}'"

It works perfectly for me, but I am the only one using my pc, so the home path isn't an issue, if they are many users, I don't really know how to do...

Hope it helps you

Offline

Board footer

Powered by FluxBB