Saturday, April 20, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 44140  / 3 Years ago, fri, june 18, 2021, 12:38:09

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.


More From » command-line

 Answers
2

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.


[#33137] Sunday, June 20, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
biryanrownies

Total Points: 396
Total Questions: 90
Total Answers: 106

Location: Saint Lucia
Member since Sun, Sep 5, 2021
3 Years ago
;