Open file from terminal in specific application

Solution 1:

xdg-open is, of course, designed to use the default applications. To use non-default applicaitons, I think you have three options.

1) Type programname filename as usual.

2) Do this outside of the terminal by a right-click in Nautilus and using open with.

3) Use your own script in the terminal. Let's assume you have a reasonably short list of default programs you might want to choose from.

#!/bin/bash
read filename
myvar=$(zenity --list --text="Chose a non-default program" --column="Programs" firefox gedit)
$myvar filename &

This would let you specify a file name, then choose the program to open it with. This is the minimal implementation, so it might need some additional work. But try it out.

There may not be a lot of benefits to this approach, but it gives you control over the process and options to suit whatever needs you have.

Solution 2:

There are pseudo-solutions like "Gnome's Web browser" (gnome-www-browser) or "Gnome's text editor" (gnome-text-editor). Same thing for the X server with its browser (x-www-browser) and its terminal emulator (x-terminal-emulator). There is also "editor" for the terminal text editor (nano, vi or whatever else). You can configure them with the update-alternatives line command.

But there were not real solution. A generic program for opening applications like xdg-open is made for opening files with default applications, not the only one application the user want to use at the very moment where he want to open the file. You cannot do this except changing the default application before opening the file but it is not user friendly and it does not woth getting default applications.

So the best solution for you is forgetting generic solutions and opening the file just like the specific application you want to use does.