EDIT: Comments to this post have very nice solutions, honorable mention goes to Trogdor's 3rd post using
bash -c "cat %f | grep URL | cut -d'=' -f2 | xargs firefox &"
but first place goes to Christian Schmidt for his grep 'URL=' < "$1" | cut -d'=' -f2 | xargs -n1 xdg-open
.That said, here is my original post (which may be worth it just for the gnome association circus):
-----------------------
I've a ton of
.URL
files, created by drag-and-drop from Mozilla Firefox within MS-Windows. These files are not automatically usable in Linux, which really sucks. Googling did provide the solution though, and here I'll share my notes:Create a script named
open-url.sh
(i like to store my scripts in ~/scripts/
) containing the following:#!/bin/sh
# opens Windows .URL files in your default browser
# requires: xdg-open sed grep xargs
sed 's/^BASEURL=/URL=/' "$1" | grep -m 1 '^URL=' | sed 's/^URL=//' | sed 's/\r//' | xargs xdg-open
Now make it executable with
chmod +x open-url.sh
Now you can associate .URL files with the script. This might be the hard part, as I did fight with it in gnome; however, XFCE was straight forward.
If you are having particular problems in gnome, my notes report the following:
Duplicate the file
/usr/share/applications/firefox.desktop
into /usr/share/applications/web-link.desktop
, and edit the latter to point to the script you created. Edit: You may consider using
~/.local/share/applications/
instead. I've found it's easier for gnome to find the new .desktop
here.Edit: be sure to give it an appropriate
Name=
and GenericName=
Then associate the .URL files with the
web-link.desktop
file.
Edit: Possibly the best way to associate in gnome3 is right-click the file and "Open Other" choosing the new name you've given with the
Name=
from the .desktop
previously edited. THEN, most importantly, right click the file again, then choose properties, and highlight the new name and click "Set as Default".Additionally, even though Firefox was my default browser, my environment insisted on opening with Chromium. I was forced to manipulate the xdg-open command. Below are commands that may help you:
xdg-open
xdg-settings get default-web-browser
xdg-settings set default-web-browser firefox.desktop
There is some chance, you may need to look into
gnome-open
or gvfs-open
.Edit: You can do OSX
.webloc
files too with the following script:#!/bin/sh
# opens OSX .webloc files in your favourite browser
# requires: grep awk xdg-open
# or edit for similar like gnome-open
grep string "$1" | awk -F\> '{print $2}' | awk -F\< '{print $1}' | xargs xdg-open
You may wish to read http://steronius.blogspot.com/search/label/xdg-mime%20default for setting mime-types.
Good luck.
~~~
Please consider crypto tipping: