# How to set default applications non-interactively (e.g. vlc as default for video)?

It's straightforward to set vlc as default using the GUI, but straightforward doesn't mean easy(I have to do the same thing over and over many times each time I install a new system). I just need a short command for this(e.g. set a gconf or dconf key). Please no answers like right-click and select Properties.

-

That information is stored in .local/share/applications/mimeapps.list, I save a copy of that file and copy it to new systems.

-
is there a better way of doing that? –  jrg Dec 8 '12 at 13:17

You can set the default mimetype handler with the gvfs-mime command. Unfortunately, you need to do this for each mimetype. There's no way I know to set it for all video at once.

gvfs-mime --set video/mp4 vlc.desktop


You could of course script that.

#!/bin/bash

MIMETYPES="video/x-flv video/mp4 video/mpeg video/ogg video/x-theora+ogg"

for i in $MIMETYPES; do gvfs-mime --set$i vlc.desktop
done


To makesure you get all the mimetypes that Totem is set to handle, you could parse it's desktop file for the MIMETYPES variable like:

MIMETYPES=cat /usr/share/applications/totem.desktop | grep "MimeType" | cut -d '=' -f 2 | tr ";" " "

-