Opening `.url` Files Like a Pro
Previous: Graham’s Scan Convex Hull Algorithm
Next: Local Hoogle Daemon
I go back and forth between Linux, Windows, and OS X, and I end up getting a lot of proprietary files in my Dropbox.
It’s been bugging me for a long time that there’s no xdg handler for Windows .url
files in Linux, so I finally strung one together.
A .url
files in windows looks something like this:
Simple, elegant, clean.
In order to pull the url out of a file like that, we just have to find the line that begins with URL=
, cut that line at the =
, and take the second piece.
That’s a one-liner in Bash:
Once we have the URL, we can feed it to xdg-open
to open it in the default browser.
Here’s a Bash script that does that with a few embellishments.
Remember to make it executable:
The $1
refers to the first argument, so if we invoke as openurl example.url
, then $1
will expand to example.url
.
We can try this from the command line, and you should see that it works as intended.
The last line of output is created by chromium-browser
, my default browser.
Nice, but not enough.
We ultimately want to be able to just double click on example.url
in our file manager, and then have a browser tab open with the correct URL.
The program that makes all of that work is called xdg-open
, so we need xdg-open example.url
to invoke ~/bin/openurl example.url
.
For this, we need to create a .desktop
file for ~/bin/openurl
.
We need to know the MIME-type of a .url
files, so we check real quick:
And now we can write our .desktop
file.
Finally, we just need to tell xdg to open application/x-mswinurl
types with openurl.desktop
.
Now, we can open .url
files in Linux by double clicking them.
Not sure how I’m going to do all this wiring in OS X, though.
Here are a few pages that I referenced to get this working:
Previous: Graham’s Scan Convex Hull Algorithm
Next: Local Hoogle Daemon