Splitting my time between Linux and macOS, and syncing files between the two systems, I often find myself trying to view and edit macOS-specific files on Linux. One particular frustration comes in the form of .webloc files—Apple’s custom file format for URLs. If you’ve ever dragged-and-dropped a URL on macOS, you’ve probably encountered one of these; they’re a pretty simple (if Apple-specific) format, but I’ve found them to be almost entirely unsupported on Linux.

The few options out there seem either incomplete (Opening Web Internet Location Files on Ubuntu) or overly heavyweight (WeblocOpener). With that in mind, here’s my slightly more complete set of instructions for adding support for opening .webloc files to Linux.

The approach involves creating two new files: a MIME database entry telling Linux about the existence of the application/x-webloc MIME type; and a desktop entry which provides a simple handler for the new MIME type, using xdg-open to open the URL with the default browser.

  1. Create the MIME entry in ~/.local/share/mime/packages/application-x-webloc.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
       <mime-type type="application/x-webloc">
         <comment>Webloc</comment>
         <glob pattern="*.webloc"/>
       </mime-type>
    </mime-info>
    
  2. Create the desktop entry in ~/.local/share/applications/webloc.desktop:

    [Desktop Entry]
    Name=Open Webloc Files
    Comment=Open webloc files in the default browser
    Exec=sh -c "xdg-open `plistutil -i \\"$1\\" | xmllint --xpath \\"//dict/string/text()\\" -`" -- %f
    Icon=text-html
    Terminal=false
    Type=Application
    MimeType=application/x-webloc;
    NoDisplay=true
    

    This uses a combination of plistutil and xmllint to extract the URL from the webloc property list file so you’ll also need to install these. On Fedora, you can do this as follows:

    sudo dnf -y install libplist libxml2
    
  3. Finally, update the MIME and desktop databases:

    update-mime-database ~/.local/share/mime
    update-desktop-database ~/.local/share/applications
    

After completing these steps, double clicking a .webloc file in your file manager of choice should open the link in your default browser.