Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In earlier versions of Ubuntu (10.10-) there was an option in the "open with" tab in the properties window, to add a custom command to open a file. However, this is no longer the case in Ubuntu 11.10. Is there any way that I can add these file type associations with a command of my choice rather than the applications detected by the system.

share|improve this question

8 Answers 8

up vote 14 down vote accepted
+100

As aneeshep's answer explains, the key is creating an appropriate .desktop "launcher". But there's a simpler way than doing it by hand; in many cases, you may not even need to edit the .desktop file.

Solution: Use Ubuntu Tweak

  • Ubuntu Tweak is a utility, which among other things, allows you to associate file types to be opened with a custom command. Behind the scenes, it creates a .desktop file which you can edit further for your needs, e.g. if you are using a command-line editor or program to open, etc.

In this how-to, we look at how to set up Nautilus to open .php files in the free Komodo Edit GUI text editor, which comes with a shell-installer that installs it in your home directory by default; the program/command is then /home/user/Komodo-Edit-7/bin/komodo

1. Install Ubuntu Tweak

  • Add its PPA, update and install Ubuntu Tweak from the terminal with:

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

2. Find the MIME description for your file extension

  • Before using Ubuntu Tweak, we need to find the MIME description for the file extension we're interested in.
  • Open Nautilus, find one of the files we want (here, .php), right-click on it and click on Properties:

    enter image description here

  • In the Properties window which comes up, note the text shown just after Type:; that's the MIME description we're looking for (here, "PHP Script"):

    enter image description here

3. Add a custom program to open your filetype

  • Start Ubuntu Tweak from the Dash, and click on the Admins tab on top; then click on the File Type Manager entry on the bottom:

    enter image description here

  • After the File Type Manager opens, click on All in the left sidebar, and uncheck the Only show filetypes... box at the bottom:

    enter image description here

  • Select any filetype on the right side, and begin typing the first few letters of the MIME description from Step 2 to automatically search and select your filetype:

    enter image description here

  • Double-click on your filetype, which is now selected, to edit its associated commands.

    • Click on Add, and in the Add Application window, expand the Custom Command option on the bottom
    • Type the command/program you want or use the Browse button to navigate to it and select it; here we have selected the Komodo-Edit editor from my home folder:

    enter image description here

    • Click on Add, so the new command is now the default, and then click Close:

    enter image description here

  • PHP files will now open in Komodo by default, as seen in the Properties below; press the Reset button to go back to the default for that filetype:

    enter image description here

share|improve this answer
    
Add also the information while using the solution that does not require Ubuntu Tweak (copy it from here, also there is a link that explains all .desktop options for you) and you will get 3x the rep offered! Great job (again and again and again). –  Bruno Pereira Jul 26 '12 at 12:12
11  
This looks like an awful lot of work to enable something which worked so simply for years before... :\ –  Tomislav Nakic-Alfirevic Sep 20 '12 at 13:26
1  
@TomislavNakic-Alfirevic I think this should be made as a feature request: brainstorm.ubuntu.com –  Anderson Green Dec 28 '12 at 0:30
    
Ubuntu tweak is broken for me, after I add the custom launcher it doesn't set it as default and neither does it appear in the list of available applications to select. –  wim Apr 11 '13 at 1:15
    
I did not switch from windows, in order to still needing special tweak software to do simple tasks. It's awkward... –  mondjunge Nov 13 '13 at 8:56

There is a workaround for this issue. as an example i am adding sublime(an ide) to the list.

1). Open a terminal and run this command:

 cp /usr/share/applications/gedit.desktop ~/.local/share/applications/sublime.desktop

2). Edit the new file and make necessary changes

vim ~/.local/share/applications/sublime.desktop

[Desktop Entry]
Name=sublime2
GenericName=Sublime2 - IDE
Comment=Edit text files
Exec=/home/aneesh/Sublime2/sublime_text %U
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
Icon=/home/aneesh/Sublime2/sublime.jpeg
Categories=GNOME;GTK;Utility;TextEditor;
X-GNOME-DocPath=gedit/gedit.xml
X-GNOME-FullName=Sublime2
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=gedit
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=3.2.0
X-GNOME-Bugzilla-ExtraInfoScript=/usr/share/gedit/gedit-bugreport
X-Ubuntu-Gettext-Domain=gedit

Please note that you might end up with duplicate launchers in your dash with this method. To prevent this you can add NoDisplay=true to your newly created launcher.

Save the file . That's it, done.

enter image description here

share|improve this answer
1  
I figured that out a while back as well. Totally forgot to post it here. Thanks for the answer though! Vim as default editor and mplayer as default video player now :) –  tapan Nov 3 '11 at 19:40
    
I added the MimeType= to my app's .desktop, but that did not seem to change anything. –  queueoverflow Jan 15 '12 at 19:50
    
Did not work for me in 11.10 - I received error; Could not find '/home/aneesh/Sublime2/sublime_text' –  John McKean Pruitt Apr 3 '12 at 1:00
1  
What to do when the Exec path contains a space (and you can't change that)? –  nh2 Sep 17 '12 at 15:57
1  
I second this solution is the best . don't forget %U in the exec line. I had forgotten that and it took me 10 mins more. –  vishal Aug 7 '13 at 20:41

The trick is to add " %U" in Exec command of the .desktop file. Then the program will appear in available programs list to open a file with. You can create/edit desktop files easily with alacarte. Type "alacarte" in terminal to run it, or if it is not installed you will get notified about this and asked to install it first.

share|improve this answer
    
this is correct. –  Nishant Mar 21 '13 at 8:44
    
I can confirm that this is the method that works in ubuntu 13.04 –  Sagar_R Oct 17 '13 at 23:37
    
Worked for me in 14.04. –  jouge Jun 10 at 8:42

Try typing this in your bash terminal (Ctrl+Alt+T):

mimeopen -d YourFile
share|improve this answer
    
This works great. The only problem is that I just wanted to add another program to the "open with" menu, not make it the default. As soon as I revert to eog for my images, my program is gone … –  queueoverflow Jan 15 '12 at 19:49
    
great! works perfectly! –  Vicfred Jan 2 '13 at 12:27
    
where it stores its configurations? it worked but I think it got a bit strange here because I provided a full path to the executable, that was not in $PATH –  Aquarius Power May 26 '13 at 21:59

This may do it. Try Ubuntu Tweak's file type manager.

Go to the 'admins' section, open the File Type Manager, Select 'All' file types, find and select your file type in the long list, choose edit, choose the Add button, click on the 'custom command' twisty at the bottom and type the custom command you need it to use to open the file the way you desire.

enter image description here

share|improve this answer
    
Nice, but we are looking for more details and content, maybe screenshots with an example would be nice. –  Bruno Pereira Jul 24 '12 at 22:01
    
I just added a screenshot that shows how it works. –  Jazz Jul 24 '12 at 22:19
    
I did not switched from windows, in order to still needing special tweak software to do simple tasks. It's awkward... –  mondjunge Nov 13 '13 at 8:56

For 11.10 and newer:

You open nautilus, right-click on your file, select properties. In the properties window, there is a "Open With" tab. Go there, choose your application from one of:

  • Default Application
  • Recommended Applications
  • click on "Show other applications", then select one of the "Other Applications"

Then -

  1. to make it the default program, click on the "Set as default" button or
  2. to add the program to the "Open With" list, click on the "Add" button.
share|improve this answer
    
Screenshots here would make this answer amazing! –  Jorge Castro Jul 24 '12 at 21:45
4  
This only works for applications that are already registered (via the .desktop/mime-type methods.... –  izx Jul 25 '12 at 2:31
    
the 'Add' button is disabled - how do I make it clickable? –  Anentropic Aug 8 '12 at 11:35
    
@Anentropic Have you clicked on "Show other applications"? If yes, then you need to select one of the "Other Applications", then the Add button will become clickable. Have modified the answer to reflect this. –  Sri Aug 10 '12 at 5:36
    
@Sri yes I've clicked "Show other applications" and the Add button is still disabled. –  Anentropic Aug 11 '12 at 13:06

Using mimeapps.list

Another way of modifying file type associations is through the mimeapps.list file found in ~/.local/share/applications. The advantage of this method is that a.) it doesn't depend on third-party applications b.) you don't have to modify existing system files.

Here's how to add an association or edit an existing one:

1. Finding the right .desktop file

Make sure the program you want to use has a .desktop launcher associated with it. Look through ~/.local/share/applications and /usr/share/applications to find the correlating .desktop file for your program, e.g. mplayer.desktop. If there is no .desktop file for your application, you can easily create one following the instructions provided in this answer.

2. Identifying the mimetype

Using nautilus right click on a sample file, head to properties and copy the mimetype listed under Type, e.g. audio/mpeg.

3. Editing mimeapps.list

Open mimeapps.list in gedit

gedit ~/.local/share/applications/mimeapps.list

Search for the mimetype you copied above. If it exists, append your .desktop file to the list of associated programs, e.g.:

audio/mpeg=umplayer.desktop;vlc.desktop;

to

audio/mpeg=umplayer.desktop;vlc.desktop;mplayer.desktop;

If your mimetype wasn't included in the first place, add it as a new line and, again, append your .desktop file:

audio/mpeg=mplayer.desktop;

At the top of this add a heading with [Added Associations] if it isn't there already. So, for an empty file which is just created, it will looks like

[Added Associations]
audio/mpeg=mplayer.desktop;

That's it, your application should now appear in the "Open with" dialog.

share|improve this answer

what is if you need a param for your app to open a path:

example: gdmap.desktop to open a folder with gdmap

Exec=gdmap -f %U

But now I cant start gdmap from application list... ?

What is the right syntax?

share|improve this answer

protected by Community Oct 24 '11 at 0:49

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.