create desktop item for all harddrives mounted.
Posted: 15 May 2011, 19:29
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.
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.
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
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.