Ubuntu: How to get custom desktop file to be the default program for certain files


I have written a python wrapper for vlc that sits as an appindicator and monitors keystrokes to vlc and loads next/prev files in folder. I have the script working from nautilus scripts. Now I need this script to be the default opening program for video files. How do I have achieve this?
I have already made a .desktop file and put it in

This is the contents of the desktop file.

[Desktop Entry]  Name=vlcwrapy-nix  Icon=vlc  Type=Application  Exec=/home/thekindlyone/projects/vlcwrapy-nix/vlcwrapy-nix.py  

The desktop file shows up on Dash fine.
But in the open with context menu of nautilus of a file, vlcwrapy-nix does not show up.
Please help.
PS: I need my script to get the name of the file that was double clicked as argument.. and the working directory to be the directory the double clicked file is in(just like nautilus-scripts behaves)


I'm not sure about getting Nautilus to change it's default open-with program (on Thunar it's in the right-click menu, open with other, change default, but that doesn't really help here)...

I have a bunch of .desktop files in /usr/share/applications/, tried copying your .desktop file into there? Or ~/.local/share/applications/ ?

I also have a file in my home ~/.local/share/applications/defaults.list that has many listings like this:

[Default Applications]  audio/mpeg=vlc.desktop  video/x-theora+ogg=vlc.desktop  application/pdf=evince.desktop  

After you get your custom .desktop file into the right place, editing this defaults.list file to use the new .desktop might be the way to go.

OR you could change your /usr/bin/vlc file to be your script (or a link to it) instead of the real vlc? Then you'd probably have to change the script to run the new "real" vlc (renamed to /usr/bin/vlc-real for example. Then anytime anything tries to run vlc they'll run your custom script instead.


OK, Solved it!. The problem was with the desktop file. in the exec line, I had to add a %f for nautilus to show it in open with menu.

Exec=/home/thekindlyone/projects/vlcwrapy-nix/vlcwrapy-nix.py %f

Here is a video demonstration, if anyone is interested.


I use ubuntu tweak to edit file associations:

sudo add-apt-repository ppa:tualatrix/ppa    sudo apt-get update    sudo apt-get install ubuntu-tweak  

Let me know if it works for you.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »