I use xdg-open
a lot in the terminal; this opens a file in the default application. However, sometimes I'd like to open a file in a different (non-default) application. Is there a way to achieve this from the terminal?
(Obviously, some applications can take a file as an argument, e.g. vlc /path/to/movie.mp3
, but I'm looking for a more generic way that works in all situations, similar to xdg-open
.)
An advantage of an xdg-open
-like command is that the terminal window can be closed after opening the file/application. However, if I use (e.g.) vlc /path/to/movie.mp3 &, then I'll need to keep the terminal window open.
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.
No comments:
Post a Comment