How to set default apps in Gnome via command

Is there a command that can change the default apps?
I mean specifically this setting:

Changed the association from Photo Viewer to gThumb. But I’d like to do this via a command as well to automate it during system (re-) installs.

3 Likes

I think gsettings or dconf would be the way to script this :thinking: , which is how you would do Shortcuts as well in dconf.


Just checked dconf editor and could not find it. So i assume it’s gonna have to be gsettings.

edit :

I had better success with :

xdg-mime query default 

application/  audio/        font/         image/        message/      model/        multipart/    text/         video/

which for example returned :

xdg-mime query default video/mp4
org.videolan.VLC.desktop

2 Likes

Yes but that is not what I meant. I know I can use xdg-mime to change the default application per file-type.
What I am referring to is a command to change the default application for an entire category of file types such as images/photos.

I already did dconf watch / while changing the setting in my screenshot, but nothing appeared so indeed no gsettings/dconf solution will work.

2 Likes

Take a look to ~/.config/mimeapps.list

At least when I set Chrome as Default Web App, in such file I get

...
x-scheme-handler/https=com.google.Chrome.desktop
...

When I switch back to Firefox, I get

...
x-scheme-handler/https=org.mozilla.firefox.desktop
...

More info: Override the default registered application for individual users

Edit. Hint: explore gio command

4 Likes

Again thats only for 1 type. In this case https.

In Gnome Settings you can change the default image viewer for all image types. Thats a totally different story. I wonder what kind of action or command is behind that?

I’m not too sure what to look for, but I’m thinking GNOME’s GitLab might have a file that has hints.


I ran into something similar on Xfce and couldn’t quite figure out how to tell an app just to handle every format it could. Instead of going further with that; I know the specific file formats I mess with so I just have a bunch of one-liners I run once on a fresh install (no guess-work):

gio mime 'text/plain' 'org.xfce.mousepad.desktop'
gio mime 'image/png' 'org.xfce.ristretto.desktop'
gio mime 'application/pdf' 'org.gnome.Evince.desktop'
gio mime 'application/epub+zip' 'com.github.johnfactotum.Foliate.desktop'
1 Like

@Espionage724, I’ve frequently wondered why that isn’t the default. Do you now know? I’d like to apply that to VS Code.

This conversation got me curious about how the Gnome Settings app was doing this under the hood, so I poked around their GitLab repository to look at the code and do some experimenting locally.

The TLDR from what I can tell is that the Settings app isn’t doing anything special and is ultimately just updating your ~/.config/mimeapps.list file as pointed out by @alciregi. I do not see a way to do it via the command line, sorry.

For automation, I would suggest just backing up your mimeapps.list and copying its contents into that of the fresh installation.

2 Likes