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.

Sometimes while going to open a file from Nautilus I do not find the intended application in "open with" menu on right click. Or the desired application remains hidden in a long list of applications. It becomes difficult to find it quickly.

Prior to Ubuntu 11.04 there was a nice feature "Use a custom command" under "open with" menu on right click on a file. One could able write a command in the box to open a file with a custom application. This option is no longer available in Nautilus after Ubuntu 10.10.

enter image description here

Question:

Can I have a similar "Use a custom command" dialogue box on Nautilus so that I can open a file writing any custom command in a box as shown in the above picture?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Here is a small Nautilus script which gives you a "Use a custom command" dialogue box on Nautilus.

The Script

  • Save the following script as Open with custom command in your ~/.gnome2/nautilus-scripts/. If you are using Ubuntu 13.04 or above, you need to put the script in ~/.local/share/nautilus/scripts/
#!/bin/bash
var=$(zenity --entry \
--title="Add Application" \
--text="Use a custom command" \
--width="320")
if [ $? -eq 0 ] && [ "$var" ]; then
    $var "$1"
else
    exit 0
fi
  • Give the script execution permission. It is important, otherwise no change will take place. You can use in terminal,
chmod +x ~/.gnome2/nautilus-scripts/Open\ with\ custom\ command

Or you can do it from GUI. Right click on the script, then go to Properties >> Permissions and check the box corresponds to Execute to give the script execution permission.

How it looks like

After that when you right click on a file you could see an option Scripts followed by another option under script Open with custom command.

enter image description here

When you select the option Open with custom command, you will get a dialogue box like,

enter image description here

You can write a command in the box to open the file.

Useage

You can open any file by entering corresponding application's command only in the dialogue box.

For example you can open a .txt file using gedit or a .pdf file writing evince in the dialogue box.


Some Other Usage

Open file as root:

If you want to open a file as root, just use gksudo before your command. To open a .txt file as root you can use in the dialogue box,

gksudo gedit

Opening an unknown file:

If you are not sure which application to use to open an unknown file, you can use in the dialogue box,

xdg-open

Opening a file with a Terminal Application:

If you want to open a text file using vi, you can use in the dialogue box,

gnome-terminal -x vi

Note:

To use gksudo you need to have gksu installed. In Ubuntu 13.04 onwards it is not install by default. You can install it using,

sudo apt-get install gksu
share|improve this answer
1  
This is nice. First I thought that this is a duplicate of How to customize the context menu in Nautilus?, but not, this is more than that! –  Radu Rădeanu Mar 9 at 15:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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