I’m on an adventure. I have run a farm of Linux-based servers for decades, but for my desktop experience I have been using Macintosh computers since 1984. I’m a big fan of FOSS, and after I retired and could afford to have my workflow disrupted, I decided to switch to Linux for my desktop.

In the nearly 40 years that I have been using various incarnations of the Macintosh operating system, I have generally been content. It was certainly a better fit for my style than the 800 pound gorilla of OS’s out of Redmond. Still, several times I’ve been burned — badly — when Apple pulled features or software upon which I had come to rely. With open source, if a developer abandons a project then someone else can continue to maintain a fork of it or I can just do so myself (or, if that’s beyond my capabilities, I can at least hire someone to do so). FOSS also means that, even if the software isn’t available, the data formats are open to facilitate migration. Forcing people into subscriptions or to use cloud services is almost as bad as killing products altogether. I have become less and less comfortable trusting Big Tech to protect me and my data.

So I bought a new Framework laptop (repairable! upgradable!) and installed a Linux disto (Fedora, but not for any particularly relevant reasons). I then used rsync to make a complete copy of my Macbook Pro storage. I didn’t pick and choose, as I didn’t want to leave anything behind.

Getting in the flow of things on the new machine wasn’t easy, with a lot of decades-long habits to re-train, but it also wasn’t as hard as I’d feared. For one thing, I’d learned my lesson and had assiduously avoided embracing new proprietary or cloud-based solutions. The Libre Office suite was able to handle my Pages and Numbers files, and I was already using cross-platform solutions for much of my work (Standard Notes, FreeCAD, Blender, Thunderbird…). I really miss BBEdit and LaunchBar, but not much else. Three types of files, though gave me grief.

Apple alias files

Instead of the symlink files most Unix-like OS’s employ, Apple created a proprietary alias file that adds some robustness and flexibility to the concept of file aliases. At first, I was stymied because Nautilus (the default file browser for the Gnome desktop environment) didn’t recognize them. Fortunately, I discovered that Dolphin, the file browser default for KDE, follows most aliases just fine. In my case, the aliases that don’t work aren’t all that important, and I can easily replace them with symlinks as the need arises.

.command files

I’d written a lot of bash shell scripts for macOS. They’re almost all cross-platform, but running them on the Linux desktop is a multi-step process. On macOS, if you give a text file a .command extension, the system will run it as a shell script when you double-click it. On Linux, that becomes a multi-step process: right-click and choose “run”. Or, more commonly, double click it, watch it open in the text editor, utter an expletive, close the text editor, then right-click and choose “run”. It doesn’t seem likely that I’ll ever fully suppress the reflex to just double-click, so I created a special .desktop file  in ~/.local/share/applications/shellrunner.desktop:

[Desktop Entry] 
Name=shell script runner 
Comment=Runs executable files 
Exec=gnome-terminal -- %f 
Type=Application

Once the file is in place, you can right-click any .command file, choose “Open With…”, then pick “shell script runner” and tick the box that says “Always use for this file type.” From then on, double-clicking any .command file will try to run it as a shell script.

.webloc URL files

I never liked the internal URL managers that came with the big-name browsers, and I wanted portability, so I just managed my URLs by dragging the web address onto the macOS desktop and organizing them in folders. I found it a fast, intuitive, and effective way to manage URLs that is cross-browser and flexible. Alas, the .webloc files that macOS creates in this case won’t open in Linux with a double-click. Worse, there are at least three totally different internal formats for .webloc files.  I found an open-souce program to open them, but it seems to only work on Debian-derived distros, so a no-go on Fedora.

The solution, mostly, turned out to be a one-line script but requires two files. Create this file, being careful that the “perl…” statement all ends up on one line: /usr/local/bin/weblocr :

#!/usr/bin/bash 

perl -gpe <"$1" "s/(.*(https?:\/\/[a-zA-Z0-9][-a-zA-Z0-9+\/\#_.:%]+).*)/\2/s" | xargs firefox

then create another file in ~/.local/share/applications/weblocr.desktop :

[Desktop Entry] 
Name=webloc file opener 
Comment=opens Apple '.webloc' files 
Exec=/usr/local/bin/weblocr %f 
Type=Application

This handles the vast majority of .webloc files in my system, and I hope yours as well. There are, however, issues of which you should be aware if you choose to use this crazy script…

The most common type of .webloc file (on my system) uses a binary file that I suspect is some kind of compressed plist file, though I’m not really sure. Feeding a binary file to a perl regular expression is not guaranteed to work, though it doesn’t fail on any of the several hundred binary .webloc files I have.

The second version of .webloc files are coded in xml. My script is a cheap, hacky way to extract the URL. It would be possible to write a perfectly-valid xml file that would return bogus results. Again, though, “it works on my machine.”

The third version of .webloc files store their data in the macOS “resource fork,” a repository for metadata. This goes against all kinds of guidelines that Apple themselves have given to developers over the years, but that’s just par for the course. There is an option in the macOS version of rsync that I could have used to preserve resource fork data, but I didn’t.  Nor am I at all disposed to going back and recovering those now-lost bookmarks (which show up on Linux as just empty, zero-byte files). All the ones I have checked so far point to sites that are now only available on the Internet Wayback Machine, so I’m assuming Apple started heeding their own advice a long time ago and that all my newer bookmarks will work.

One other thing: the whole reason I tried to come up with a simple, single-line hack to do this is that I was hoping to be able to put the code on the “Exec=” line of the .desktop file and avoid having to create a second file. Theoretically, it should be possible. The Exec line takes only a single command, and passes everything else as argument, but one should be able to do something like:

Exec=bash -c "perl -gpe <\"%f\" \"s/(.*(https?:\/\/[a-zA-Z0-9][-a-zA-Z0-9+\/\#_.:\%]+).*)/\2/s\" | xargs firefox"

Alas, it doesn’t work, I suspect because the quoting interferes with the expansion of the “%f” filename variable. The quoting gets pretty thick in that statement. If anyone smarter about .desktop files knows a solution to this, please let me know.