Page 1 of 1

create desktop item for all harddrives mounted.

Posted: 15 May 2011, 19:29
by Proxx
crashman requested a script to create desktop icons for all mounted harddrives.

i have started on the script it is partially ready. the links does not work.
there are frends with me at home. and to not bore them to death i cannot finish the script this time.

Code: Select all

#!/bin/sh

function fadd {
for i in $(cat /etc/mtab |cut -d' ' -f1 |grep -v "sysfs" |grep -v "proc" |grep -v "fusectl" |grep -v "aufs") ;do # i think that this isnt the best way. (mayby /proc/self/mount* or mtab/fstab is a better solution)
	PICON=0
#	if [ ! -f ~/Desktop/$hdp.desktop ];then
      hdp=$(echo "$i" | cut -d'/' -f3)
      echo "[Desktop Entry]" >> ~/Desktop/$hdp.desktop
      filesys=$(cat /etc/mtab |grep $hdp |cut -d' ' -f3)
      if [ "$filesys" == "vfat" ];then echo "Icon=hd" >> ~/Desktop/$hdp.desktop ;PICON=1 ;fi
      if [ "$filesys" == "fuseblk" ];then echo "Icon=hd-windows" >> ~/Desktop/$hdp.desktop ;PICON=1 ;fi
      if [[ "$filesys" == ext? ]];then echo "Icon=hd-linux" >> ~/Desktop/$hdp.desktop ;PICON=1 ;fi
      if [ "$filesys" == "iso9660" ];then echo "Icon=cdimage" >> ~/Desktop/$hdp.desktop ;PICON=1 ;fi
	  if [ "$PICON" == "0" ];then echo "Icon=hd" >> ~/Desktop/$hdp.desktop ;fi
	  echo "Name[en_US]=$hdp" >> ~/Desktop/$hdp.desktop
      echo "Name=system:/media/$hdp" >> ~/Desktop/$hdp.desktop
      echo "Type=Link" >> ~/Desktop/$hdp.desktop
      echo "URL[\$e]=system:/media/$hdp" >> ~/Desktop/$hdp.desktop
	  echo "$hdp - $filesys"
#  fi
done
}
if [ "$1" == "-d" ];then if [-e ~/Desktop/$1.desktop ];then rm ~/Desktop/$1.desktop ;fi ;exit 0 ;fi
fadd

# it will be nicer if the desktop links will disappear when the drive is unmounted.
# maybe use functions in the script for options to do on boot,unmount and mount.
# /etc/udev/rules.d/ is the appropriate way to do that. i wil make a setup for that tomorrow
# RUN+="/usr/bin/this_script mount/unmount" to add / remove a link
edit: updated the code. this time it is working!

going to improve the script to detect cdrom ntfs fat usb or network media and use the appropriate icon
going to using udev to detect mount / unmount events to add / remove desktop icon.

Re: automaticly create desktop item to all harddrives.

Posted: 16 May 2011, 18:26
by crashman
Thank you Proxx

Testing your script and work :good: but i have three partition sda1-NTFS sda2-NTFS sda3-EXT4 and your script show only icon for sda3 partition.

regards

Re: automaticly create desktop item to all harddrives.

Posted: 16 May 2011, 18:34
by Proxx
i know that there are some flaws in the script.
are all the mounts done in the /mnt dir ?

i wil edit the script to search in mtab so that the script wil detect mounts on other dirs than /mnt

Re: automaticly create desktop item to all harddrives.

Posted: 16 May 2011, 18:38
by crashman
In my laptop porteus always mount all drivers, your script mount from 'system:/media/sda3' path, unmount not work.

Re: automaticly create desktop item to all harddrives.

Posted: 16 May 2011, 19:11
by Proxx
you mean that the script does not remove the icon from the desktop when a drive is unmounted ? im working on that.
i fixed the script so that it will show all your drives. working on ntfs icon as we speak (need to format flashdrive to ntfs to test =])

to let the icon be removed on unmount i need to edit the /etc/udev/rules.d/file im testing this as we speak.

Re: create desktop item for all harddrives mounted.

Posted: 16 May 2011, 23:24
by brokenman
Sounds like a useful script.

Also you may consider this:
Right click/go to Configure desktop--> Behavior---->Device icons/ and check the box saying "Show device icons"

Re: create desktop item for all harddrives mounted.

Posted: 17 May 2011, 10:24
by Proxx
brokenman do u know why there are like 4 different things to manage the auto-mounting ?
it is getting me nuts. (but i learned a lot from it)

udev/hal/udisks/pcmanfm :%)

whoho: im a white ninja from now

Re: create desktop item for all harddrives mounted.

Posted: 17 May 2011, 19:34
by crashman
@Proxx
Thank you very much yor script work now :) is very usefull :good:

Re: create desktop item for all harddrives mounted.

Posted: 24 May 2011, 19:27
by brokenman
brokenman do u know why there are like 4 different things to manage the auto-mounting ?
Not exactly sure what you mean here by automounting. Do you mean during boot time, or when you plug something in?