Opening Your Windows URL collection in Ubuntu
If you are migrating from Windows to Linux there is a chance that you have a few .url files that you've kept over the years. If you have just a couple then this may not be a big deal to you. However if you are like me and have hundreds of them then this solution may be worth your while. If you take out all the time I took to study every nuance of everything I did (hey I really want to understand this stuff), then it only took me about ten minutes to put this soltion into place.
The guy who did this certainly needs his own post in this week's tip of the week. The only thing I can take credit for is spending a couple of hours to find this solution and then verifying that it works in Ubuntu 10.04 (a.k.a Lucid). Without further ado here is oomingmak's instructions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The explanation of how I discovered the various pieces of the jigsaw puzzle (that finally allowed me to get .url files working on Linux) can be found in my earlier posts in this thread. However, below is a summary of the steps that I took to get it working.
As I said before, I'm a complete novice when it comes to Linux, so my method might not be the most efficient way of providing this functionality, but no one else has come up with any kind of solution, and at least I know that my method definitely works.
Apologies if my instructions are a bit too simplistic, but you did say that you are a total noob, so I've tried not to make any assumptions about what you already know how to do on Linux. By keeping my instructions simple, it should hopefully make it easier for other newbies to understand and follow as well.
1. Create a script file that can read and extract the web links contained within a .url file.
The following script is the one that I created (after much struggling) based on the 'nsurl' code that I found on the internet. The version below contains the fix for the 'URL truncation' problem that was mentioned earlier in this thread.
Right-click on your Desktop and select 'Create Document' and then 'Empty File'. This will create a new blank text file. Open the file and paste the the script shown below into it. Save the file and name it: fx-url
#!/usr/bin/perl
# Script to make Microsoft Windows Internet Shortcuts (*.url) work on Linux.
# Oomingmak fixed version. This script now works properly.
# It no longer cuts off the last character of the URL.
# Open up the file
open(F,"<$ARGV[0]") or die "$0: Could not load Internet Shortcut file $ARGV[0]!\n";
# Find the URL
while($in = <F> and not $url) {
chomp($in);
if($in =~ m/\s*URL\s*\=\s*\S*\s*\015*/) {
$url = $in;
$url =~ s/\s*URL\s*\=\s*//; # Filter out the beginning stuff
$url =~ s/\s*\015+//; # Filter out the nasty DOS carriage return!
}
}
system "firefox $url &";# or die "$0: Could not open $netscape\n"
.
2. Make the script executable.
Once you have created and saved the script, you need to make it executable so that it can run like a program. To do this, open a command line terminal window and use the 'cd' command to change directory to where you have the script stored (for example: cd Desktop) and then type:
sudo chmod a+x fx-url
.
3. Place the executable script into the /usr/bin folder.
You must have 'root' privileges in order to put anything in /usr/bin (because it's a system folder). This means that you must use the 'sudo' command when issuing the file move instruction. Copy the command shown below and paste it into the terminal window:
<font color="Black">sudo mv fx-url /usr/bin/fx-url</font>
.
4. Create a symlink to the executable script (in the same /user/bin folder).
To create a symlink to the fx-url file, paste the following command into the terminal window:
sudo ln -s /usr/bin/fx-url /usr/bin/'Web Browser'
5. Create a Mime type to recognise .url files.
A 'mime type' must exist for each file type. Mime types are what the system uses to detect the presence of a certain type of file. We therefore need to create a mime type for .url files so that the system will be able to identify them in future. By far the easiest way to work with mime types is to use a program called AssoGiate.
If you are using Ubuntu 7.10 (Gutsy Gibbon) or later, you can easily install AssoGiate by using the 'Add/Remove' item on the 'Applications' menu. Just search for 'AssoGiate', install it, and then skip to step number 6. (Make sure that you have selected 'Show: All Available Applications' in the 'Add / Remove' dialog, otherwise AssoGiate won't show up in the search results).
For earlier versions of Ubuntu, you will need to install AssoGiate from source code using the instructions below:
- Install the libraries that are needed in order for AssoGiate to work. You do this by pasting the following into a command line terminal:
- Download the AssoGiate installation package (click the link >> Download AssoGiate).
- Unpack the downloaded file and follow the 'Basic Install' instructions that are located in the file called INSTALL. See my post here if you require more information.
6. Create a url file type.
Open AssoGiate. Click the 'New' button on the toolbar to create a new Mime type. Enter the settings exactly as they are shown below and then save your changes:

For the Default Icon setting (shown above), just use the browse button .
. to select any icon of your choosing.

7. Associate the executable script with the .url file type.
Now that you've created a url mime type, your system knows how to recognise which files are url files, but it still doesn't know what it should do with them once it's identified them. We therefore have to associate the .url file type with the executable script that we made earlier. To do this, find any .url file, right-click on it and choose the 'Properties' menu. Go to the 'Open With' tab and press the 'Add' button. (An 'Add Application' window will appear). At the bottom of the Add Application window is an option called 'Use a custom command', click this option and browse to /user/bin and then select the symlink file that you created in step number 4 - [for example: /usr/bin/Web Browser ]. Click the 'Add' button to save your changes.
8. Make the associated action the default option.
If you don't specify a 'default' action, then your .url files won't be activated automatically when you click on them (you will instead always have to right-click the .url file and choose the required option from the context menu). To make opening in Firefox the default action, go back to the 'Open With' tab of any .url file (Right-click on .url file > 'Properties' > 'Open With') and click the dot to the left of the entry that you just added (e.g. Web Browser). Next, open a Nautilus file manager window and go to the 'Edit' menu and select 'Preferences' then 'Behavior'. In the 'Executable Text Files' section, make sure that 'View executable text files when they are clicked' is selected.
To check that the default option change has worked properly, restart X (by pressing: Ctrl + Alt + Backspace) then log back in to your desktop and right-click on any .url file. You should now see the top entry of the .url context menu saying: Open with "Web Browser".
Clicking a .url file should then automatically start Firefox and go to the specified web site. If Firefox is already running then the web page will just open in a new tab.
Done!

Labels: Linux, Tip of the Week, Ubuntu


0 Comments:
Post a Comment
<< Home