Add custom command in the open with dialog?

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


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
    

    Update: Check this question for updated instructions for newer Ubuntu releases

    • How do I 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


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.

Tags:

Gnome

Nautilus