Contact
Offices

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/fix_url.sh

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

#!/bin/bash
 
(
    IFS=$'\n'
    files=$(find . -name *.url)
    for fl in $files; do
        NEWFILE=${fl}.desktop
        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}"
    done
)

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

chmod +x /usr/local/bin/fix_url.sh

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
/usr/local/bin/fix_url.sh

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

Image CAPTCHA