Equivalent of .URL file on Ubuntu
In Ubuntu an URL shortcut is stored in a .desktop file as follow (for example):
[Desktop Entry]
Encoding=UTF-8
Name=Link to Best Practices Software engineering
Type=Link
URL=http://abdennour-insat.blogspot.com/
Icon=text-html
If you still want to open your Windows URL files in Ubuntu, here is described how you can do it:
- How to Open .url Internet Explorer Shortcuts in Ubuntu Using Firefox.
The Perl script given in that article appears to be broken, but the following code should do the same thing correctly:
#!/usr/bin/perl
# Script to make Microsoft Windows Internet Shortcuts (*.url) work on Linux.
my $browser = 'sensible-browser'; # use the system default browser
while (<>) {
# match any line of the form "URL = something-without-spaces"
if (/^\s*URL\s*=\s*(\S+)\s*$/) {
exec $browser, $1; # successful exec never returns
die "$0: could not launch $browser: $!\n";
}
}
In Unity we have .desktop files for defining items on the launcher, desktop, or other locations. To create these see the following question:
- How can I create launchers on my desktop?
A link to an internet file may have an entry as simple as the following
[Desktop Entry]
Encoding=UTF-8
Name=Internet Link
Type=Link
URL=<url>
Icon=<icon to display>
You can create such a file with a text editor, or much easier by simply dragging and dropping a bookmark from your browser to the desktop.
However keep in mind that such a simple .desktop file will not automatically open the given URL in a browser if the target is e.g a text document, or image. To overcome this see the following question:
- Desktop internet shortcut opens as text file
In case we do need to open .URL files more often (e.g. from a shared drive) we may also run a bash script similar to this to open them:
#! /bin/bash
# opens Windows URL file submitted as command line argument in browser
source $1
xdg-open $URL
The command not found
error from this script can be ignored or sent to /dev/null
. If we must then we could associate this script to a Mime type for the extension URL to double click open an URL file.
You can make your Linux file manager open .URL file in your default browser. This is particularly useful for people who share files between Windows and *nix machines. To do this create a script file let's call it mswin-urlfile
(or what ever you like) in /usr/local/bin
(or your preferred folder). Change permission: chmod +x /usr/local/bin/mswin-urlfile
#!/usr/bin/bash
if [ "$1" == "" ] || [ "$1" == "--help" ] ; then
echo "$(basename "$0") URLFILE - opens a .url file in the default browser"
else
sed 's/^BASEURL=/URL=/' "$1" | grep -m 1 '^URL=' | sed 's/^URL=//' | sed 's/\r//' | xargs xdg-open
fi
To test use it manually from a shell prompt using:
mswin-urlfile test.url
Next you will need to configure file manager to call mswin-urlfile
when opening a .URL file type. This works across all *nix and shells allowing you to open your .URL files from within your file manager. Exactly how to do this depends on the file manager you use. Lookup "file association" for the specific file manager you use.
For example Nautilus file manager is mentioned at 369967 and create a mimetype for the .url extension
Open Applications > System Tools > File Types Editor, and click the New button. Enter the following information in the corresponding tabs:
► General: Category: Text and source code
Name: x-url
Description: Microsoft Internet Explorer Shortcut
You can choose an icon for the .url file-type via the browse button […] – if you don’t have any, there are some at the bottom of this post that you can save to a folder like /home/yourusername/Settings/Icons.
► Filenames:
Filename pattern: *.url
► File contents:
When you click +Add, you’ll see more than one data entry field, but all you need to worry about is the Value: one.
Value: [InternetShortcut]
Now your system knows what .url files are, but it still doesn’t know what to do with them. You now have to associate the .url extension with the executable script fx-url, so right-click any .url file and go to Properties > Open With. Click the Add button, and at the bottom of the “Add Application“ window you’ll see the “Use a custom command“ option; click this, then either browse to /user/bin and select the symlink you created, or enter /usr/bin/Web Shortcut Browser (or the appropriate name if you changed it). Click the Add button to save your changes (but leave the “Properties“ window open as you’ll need it in the next step).
Now you need to make the associated action the default option for double-clicking, otherwise you’ll have to right-click .url files and choose the required option from the context menu. To make opening in Firefox the default action, in the Open With tab of the “Properties“ window, click the dot to the left of the entry you just added (eg: “Web Shortcut Browser“), then click Close.
open any Nautilus (file manager) window and go to Edit > Preferences > Behaviour. In the “Executable Text Files“ section, make sure that “View executable text files when they are opened“ is selected. Click Close, and it is done (you may need to log out or reboot for the changes to take effect). Now when you right-click any .url file, you should see “Open with Web Shortcut Browser“ as the top entry of the context menu, and it will be the default action for double-clicks.
I use a different file manager so I have not tested the above Nautilus instructions.
I prefer to keep using URL files as I use a mixed environment Android + app to open or create URL files; Linux + script (above) to open URL files; Windows (built in URL file support). Alternatively, you could convert every system to just use bookmark files and sync them, but builtin browser syncing has messed up my bookmarks more than once. If you use different browsers (eg Chrome, Firefox, Brave) on different system syncing is not simple.