Menu linux open with

Add custom command in the open with dialog?

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.

7 Answers 7

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

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 🙂

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.

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

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
Читайте также:  Wpa2 hacking with kali linux

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

    enter image description here

    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:

Источник

How to add «open with custom command» option in right click menu of Nautilus

enter image description here

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. 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?

1 Answer 1

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

Save the following script as Open with custom command in the following directory

  • ~/.local/share/nautilus/scripts/ (Ubuntu 13.04 or above)
  • ~/.gnome2/nautilus-scripts/ (Ubuntu 12.10 and below)
#!/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 ~/.local/share/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.

Читайте также:  Java utf 8 encoding linux

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.

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,

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,

Opening a file with a Terminal Application:

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

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,

Источник

Add open with VS Code to context menu in Ubuntu

In windows, we have an option: adding «Open with code» action to context menu, this allows us to open any file or folder with VS Code. Is there any way to add this feature in Ubuntu?

6 Answers 6

wget -qO- https://raw.githubusercontent.com/harry-cpp/code-nautilus/master/install.sh | bash 

Just run this in your terminal, and it will add open with VS Code in context menu for Ubuntu 18.04 LTS.

Edit: Works as well for Ubuntu 20.04 LTS, 20.10 and 22.04 LTS.

On my distro (Pop!_OS 20.10) I had to install the python3-nautilus package in order to get it to work. You can do that with sudo apt install python3-nautilus .

What you need to do is install Nautilus Actions

command

in menu

NOTE ❗ ❗ Modern version of Nautilus Actions (nautilus-actions package in trusty (14.04 LTS), xenial (16.04 LTS), artful (17.10)) are named as FileManager Actions (filemanager-actions package, it is not yet packaged in Debian and Ubuntu — see at repology.org).

sudo add-apt-repository ppa:daniel-marynicz/filemanager-actions sudo apt-get install filemanager-actions-nautilus-extension 

NOTE 2 As of Ubuntu 19.04, the package is filemanager-actions.

sudo apt-get install filemanager-actions 

«Package nautilus-actions is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source»

Читайте также:  Аналог excel on linux

@MichaelCole Sorry ! Modern version of Nautilus Actions (nautilus-actions package in trusty (14.04 LTS), xenial (16.04 LTS), artful (17.10)) are named as FileManager Actions (filemanager-actions package, it is not yet packaged in Debian and Ubuntu — see at repology.org). ** sudo add-apt-repository ppa:daniel-marynicz/filemanager-actions ** sudo apt-get install filemanager-actions-nautilus-extension orginal post askubuntu.com/a/1031746/843203

This might be a long shot but. when opening vscode with right click actions from filemanager action, it does not import all of the bashrc $PATH. For example, if I right click for ‘Open with Code’ and try to debug a javacript file, vscode will say it can not find Node.js. However, when I open vscode normally, full $PATH is exported and can then debug javascript normally. Any idea why the right click aciton is missing $PATH export?

I was able to find this vscode extension for nautilus written by Crazy0 that lets you do this.

The steps can be found in that github gist, which are:

  1. Go to the gist.
  2. And do the following (also found in the head section of that gist):
    • Place me in ~/.local/share/nautilus-python/extensions/ , restrart Nautilus, and enjoy 🙂
    • mkdir -p ~/.local/share/nautilus-python/extensions && cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && nautilus -q

Just tested on Ubuntu Bionic and it works great.

If you’re on 20.10 and you’re running this script:

wget -qO- https://raw.githubusercontent.com/cra0zy/code-nautilus/master/install.sh | bash` 

You’ll need to install python3-nautilus because python-nautilus isn’t in non-LTS versions of Ubuntu.

Simply install the python3 version of python-nautilus

sudo apt install python3-nautilus

Then restart nautilus (this will close all nautilus folders)

The last command did it for me. Also, python3-nautilus wasn’t found, so I installed python-nautilus instead.

1.Create a file ~/.local/share/nautilus/scripts/open-in-code.sh with this content:

#!/bin/bash if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS if [ $# -eq 1 ]; then destination="$1" else zenity --error --title="Error - Open in Visual Studio Code" \ --text="You can only select one file/directory." exit 1 fi else destination="`echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed 's/^file:\/\///'`" fi # It's only possible to go to local directories if [ -n "`echo "$destination" | grep '^[a-zA-Z0-9]\+:'`" ]; then zenity --error --title="Error - Open in Visual Studio Code" \ --text="Only local directories can be used." exit 1 fi exec code "$destination" 

2.Add execution permission to the file:

 $ chmod +x ~/.local/share/nautilus/scripts/open-in-code.sh 

4.Right-click on a file or directory, you will see this:

Источник

Оцените статью
Adblock
detector