nitromanrc
August 10th, 2008, 10:11 PM
well...the title pretty much says it...I wrote this little script that does that does that... so here it is
#!/bin/bash
##A script to convert windows XP (haven't tested other versions) .url files to a desktop website link for gnome.
##will convert all .url files in the current folder (up to 99, doesn't support 3 digits, however can be edited to do so if needed)
##Written by Dean Lovering
##Feel free to make suggestions, or to improve upon it yourself, send suggestions and improvements to dalovering@gmail.com please.
cat *.url |grep ^URL >> links.tmp # makes a list of all the URLs, and outputs to a temporary file called links.tmp
ls *.url | awk 'BEGIN{FS=".url"}{print $1}' >> names.tmp #makes a list of all the names of the links, and outputs to temporary file names.tmp *the awk command cuts out the ".url" from each one.
if [ $(grep -n U links.tmp | tail -n 1 | cut -c 2) = ':' ] # if last line number (number of links) is one digit
then
max=$(grep -n U links.tmp | tail -n 1 | cut -c 1) # sets variable $max to equal the number of the last line if 1 digit
else
max=$(grep http://ubuntuforums.org/archive/index.php/t-436799.html-n U links.tmp | tail -n 1 | cut -c 1-2) # sets variable $max to equal the number of the last line if 2 digits
fi
echo max= $max
line=0
while [ $line -lt $max ]
do
line=$(($line + 1)) # sets line number to correct number
name=$(cat names.tmp | head -n $line | tail -n 1) # sets $name to equal name of link
# echo ${name} #prints name of each link in the shell, used for debugging
# prints file information into file
echo [Desktop Entry] >> ${name}
echo Version=1.0 >> ${name}
echo Encoding=UTF-8 >> ${name}
echo Name=${name} >> ${name}
echo Type=Link >> ${name}
echo $(cat links.tmp | tail -n $line | head -n 1) >> ${name} # $(cat links.tmp |tail -n $line | head -n 1) prints the name of the current link
echo Icon=gnome-fs-bookmark >> ${name}
done
# give option to delete original .url files
echo "Do you want to delete original .url files <y or n>? \c"
read del
if [ $del = "y" ] #if user said yes,
then
mv *.url ~/.trashes #move .url files to trash
echo "You chose to delete original .urls, moving to trash"
elif [ $del = "n" ]
then
echo "not deleting originals"
fi
rm links.tmp # removes temporary files
rm names.tmp
#!/bin/bash
##A script to convert windows XP (haven't tested other versions) .url files to a desktop website link for gnome.
##will convert all .url files in the current folder (up to 99, doesn't support 3 digits, however can be edited to do so if needed)
##Written by Dean Lovering
##Feel free to make suggestions, or to improve upon it yourself, send suggestions and improvements to dalovering@gmail.com please.
cat *.url |grep ^URL >> links.tmp # makes a list of all the URLs, and outputs to a temporary file called links.tmp
ls *.url | awk 'BEGIN{FS=".url"}{print $1}' >> names.tmp #makes a list of all the names of the links, and outputs to temporary file names.tmp *the awk command cuts out the ".url" from each one.
if [ $(grep -n U links.tmp | tail -n 1 | cut -c 2) = ':' ] # if last line number (number of links) is one digit
then
max=$(grep -n U links.tmp | tail -n 1 | cut -c 1) # sets variable $max to equal the number of the last line if 1 digit
else
max=$(grep http://ubuntuforums.org/archive/index.php/t-436799.html-n U links.tmp | tail -n 1 | cut -c 1-2) # sets variable $max to equal the number of the last line if 2 digits
fi
echo max= $max
line=0
while [ $line -lt $max ]
do
line=$(($line + 1)) # sets line number to correct number
name=$(cat names.tmp | head -n $line | tail -n 1) # sets $name to equal name of link
# echo ${name} #prints name of each link in the shell, used for debugging
# prints file information into file
echo [Desktop Entry] >> ${name}
echo Version=1.0 >> ${name}
echo Encoding=UTF-8 >> ${name}
echo Name=${name} >> ${name}
echo Type=Link >> ${name}
echo $(cat links.tmp | tail -n $line | head -n 1) >> ${name} # $(cat links.tmp |tail -n $line | head -n 1) prints the name of the current link
echo Icon=gnome-fs-bookmark >> ${name}
done
# give option to delete original .url files
echo "Do you want to delete original .url files <y or n>? \c"
read del
if [ $del = "y" ] #if user said yes,
then
mv *.url ~/.trashes #move .url files to trash
echo "You chose to delete original .urls, moving to trash"
elif [ $del = "n" ]
then
echo "not deleting originals"
fi
rm links.tmp # removes temporary files
rm names.tmp