Changing Windows Internet Shortcut (*.url) files into GNOME desktop files

Joseph Conway

tux.jpg Recursively finding Windows Internet Shortcut (*.url) files and changing them into GNOME desktop files Over the past few days I have finally converted my wife's computer from WinXP to Linux (Ubuntu 10.10). One of the many fine points of the negotiation leading to this was that I needed to preserve her many Internet Shortcut files. Since she has literally thousands of them, and they are sprinkled about in many a nested folder, I needed a script that could find them, and create the equivalent GNOME desktop files. The following is my solution. Perhaps not the most elegant way to achieve these ends, but it worked great for me. However I cannot promise this script will not eat your files, so please test and use at your own risk ;-) Create the following script (e.g. using vi)

vi /usr/local/bin/

Put the following in (press "i", and then type or paste):

    files=$(find . -name *.url)
    for fl in $files; do
        cp "${fl}" "${NEWFILE}"
        sed -i 's/InternetShortcut/Desktop\ Entry/g' "${NEWFILE}"
        sed -i '/^\[DEFAULT\]/d' "${NEWFILE}"
        sed -i '/^BASEURL/d' "${NEWFILE}"
        sed -i '/^IconFile/d' "${NEWFILE}"
        sed -i '/^IconIndex/d' "${NEWFILE}"
        sed -i 's/\r$//' "${NEWFILE}"
        echo "Type=Link" >> "${NEWFILE}"

Save the file by typing ":x" if you used vi. Make it executable:

chmod +x /usr/local/bin/

Test/run the new script. Do this first on an isolated test location, e.g. copy some Windows Internet Shortcut files to /tmp/windows_urls:

cd /tmp

Check out the resulting *.desktop files. Verify they look correct, and that they actually work when clicked from Nautilus, etc. If completely satisfied, change to the root of the real directory tree and re-run the script. When you are all finished, the original *.url files are still hanging around. If you want to get rid of them (again test first):

cd /tmp
find . -name *.url -delete

Hope this helps someone else!

Blog Categories: 

Add new comment