Manual default file associations on Ubuntu

settings_compUpdate: This article was written for Precise. Ubuntu 14.04 has options in the File Properties GUI to associate a file type with a command. This method works on the LXDE desktop environment too.

Ubuntu Precise didn’t provide any option to create file associations with an application by locating the application manually or using path to the application. I believe this is absolutely lame and not sure whether it will be working in the released version. Hasn’t enough freedom already been snatched by throwing away the root login? I faced an issue a few minutes back. My friend sent me a video in FLV format and I played it in SMPlayer which is set by default. When I tried to do a skip-forward SMPlayer crashed. I found that running the video manually from the terminal using MPlayer doesn’t have any issues and I can skip-forward at will. I am not interested in searching the fix for this in SMPlayer right now (may be a switch needs to be passed while invoking MPlayer). So I thought of setting the default application for playing FLV files to MPlayer. I did the following:

$ grep -inr flv *
./.local/share/applications/mimeapps.list:7:video/x-flv=smplayer.desktop
./.local/share/applications/mimeapps.list:23:video/x-flv=smplayer.desktop;

I opened mimeapps.list and changed “smplayer” in lines 7 and 23 to “mplayer”. Now it’s time to find the file smplayer.desktop and create a copy as mplayer.desktop.

$ su
Password:
# find / -iname smplayer.desktop
/usr/share/applications/smplayer.desktop
^C
# cp /usr/share/applications/smplayer.desktop \
/usr/share/applications/mplayer.desktop

Now I edited the file mplayer.desktop and changed the following lines:

Exec=smplayer %U
Name=SMPlayer
TO
Exec=mplayer %U
Name=MPlayer

I didn’t bother changing the Icon=smplayer entry as in my case MPlayer is not installed with its own icons. Now, I ran the FLV file again and Voilà! It started in MPlayer.

Update: There’s a quick (and better) way of achieving the same from the terminal using the mimeopen command, as this post explains.

Comment