Changing the default application for a file extension without changing others of the same type

I do a lot of GIS work, and for that I use QGIS, which uses a .qgz file extension for a lot of the save data. QGIS thinks it's an archive (which it is I guess, but not one I would ever open in an archive manager). If I open the properties to change the default application to open with, it asks me to select an application to open my .qgz file and other files of type "Zip archive". When I change it, it tries to open ALL archives in QGIS (e.g., .zip files). Is there a way to make it so that it ONLY opens the .qgz files in QGIS while leaving all the other zip archives alone?

a reply from AI...(yes shoot me)

On Zorin OS (which is based on Ubuntu), you can set up file associations so that only .qgz files open with QGIS while leaving other zip files unaffected. Here’s how you can do this:

Steps to Associate .qgz with QGIS:

  1. Right-Click on a .qgz File:
  • Find a .qgz file in your file manager, right-click it, and select Properties.
  1. Open With Tab:
  • In the Properties window, go to the Open With tab.
  1. Select QGIS:
  • If QGIS is listed, select it. If it’s not listed, click on Add or Custom Command to navigate to the QGIS executable, usually located in /usr/bin/qgis or /usr/bin/qgis2.
  1. Set as Default:
  • After selecting QGIS, click the Set as default button. This should associate only .qgz files with QGIS.
  1. Close the Properties Window:
  • After setting the default application, close the Properties window.

Additional Steps for Zip Files:

To ensure that .zip files open with your preferred archive manager:

  1. Right-Click on a .zip File:
  • Do the same for a .zip file, right-click it, and go to Properties.
  1. Open With Tab:
  • In the Open With tab, select your preferred archive manager (like File Roller or similar).
  1. Set as Default:
  • Click Set as default to ensure .zip files are associated correctly.

Testing:

After making these changes, double-check by opening a .qgz file to ensure it opens in QGIS, and try opening a .zip file to confirm it still opens in your archive manager.

This setup should allow you to work seamlessly with both file types without interference!

I'm not entirely sure that the above solution actually works as intended. I think the problem is that that works by changing the association between a particular program and a file extension. If the system is not aware of what qgz and incorrectly assumes it's a zip file, it won't make any difference.

You may need to manually inform the system that QGIS exists and is capable of opening such files. Normally this is done by the application itself when it's installed, but it seems that the Flatpak version for QGIS doesn't do this.

Before:

sc1

There are some nice graphical programs to do this... but unfortunately I'm not really sure which ones or how they work. So, I'll be providing step-by-step instructions instead.

Note, the file manager doesn't show hidden files/folders by default, which you need to see. Press Ctrl + H in your keyboard to toggle this them. There's also an option on the settings menu for that, on the top right corner.
Also, we do need to use the terminal at least once, so the instructions below are all terminal commands for my own convenience. However, they are easy enough to follow using a regular text editor and file manager.

NOTE: While you are in the file manager, pressing Ctrl + L in your keyboard will take you to the address bar. You can copy and paste the file locations if that's easier for you to follow along. Keep in mind that I'm using my own username, which you should of course change to your own.

  1. Navigate to:

    cd /home/zenzen/.local/share
    

    and create a new folder there (two folders, one inside another):

    mkdir -p mime/packages
    cd mime/packages
    
  2. Inside this new folder, create a new file named application-x-qgis-project.xml with the following contents:

    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
     <mime-type type="application/x-qgis-project">
      <comment xml:lang="en">QGIS Project</comment>
      <glob pattern="*.qgz"/>
     </mime-type>
    </mime-info>
    
  3. Now we need to run a terminal command to register this new file type. Launch "Terminal" from the application menu list, and run the following command.

    update-mime-database /home/zenzen/.local/share/mime
    
  4. Next, we establish the file association for qgz files and the corresponding program. This file is located in another directory:

    cd /home/zenzen/.config
    
  5. Edit the file mimeapps.list and add the following:

    [Added Associations]
    application/x-qgis-project=org.qgis.qgis.desktop
    

    There's probably something in the file already since you tried to modify it through Properties -> Open With.... If there's only a couple of lines related to the zip file and qgz file, you can safely delete the entire file and only add the two lines above. If you have other file associations however, just add the line at the bottom of the [Added Associations] list.

  6. Log out of your account, and log back in.

After:

sc2

Worked like a charm, thanks so much!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.