Executing the default application assigned to a file type, from terminal, given only file name

2

Using gnome terminal (Ubuntu 10.10), is there a way to execute the default application associated to a file type, only by typing its name, as it is possible with Windows ?

For example, say I create a mime type associated to every file with the pattern *.abc. Lets say I associate this file type to application 'my_app'.

If I have file 'my_file.abc' in current folder, what I want is that when I enter only 'my_file.abc' at the prompt, it executes 'my_app' feeding it with 'my_file.abc' as first argument. (assuming of course 'my_app' is in the path)

I appreciate this behaviour in Windows, wondering if Linux/Gnome could do that too. Thanks

kebs

Posted 2010-12-10T16:19:13.447

Reputation: 219

You might have better luck on askubuntu – RobotHumans – 2010-12-10T16:21:25.070

Well, yes, actually, I didn't know askubuntu until now. Is there a way to "switch" this post to askubuntu ? – kebs – 2010-12-10T20:55:20.147

Answers

3

You could use the binfmt_misc facility for something similar, but you're probably better off just passing it to xdg-open.

Ignacio Vazquez-Abrams

Posted 2010-12-10T16:19:13.447

Reputation: 100 516

Very interesting, I'll investigate this tool, thank you. – kebs – 2010-12-10T20:55:49.473

2

On Linux with zsh (http://www.zsh.org/) you could achieve it in this way:

$ alias -s abc=my_app

And after it zsh will always execute my_app youfile.abc when you just enter youfile.abc.

user135362

Posted 2010-12-10T16:19:13.447

Reputation:

1

I don't know of any unix shell that allows you to execute any file in this way.

On Debian or Ubuntu, see myfile or edit myfile opens a file in the application that's associated to the file type through the mailcap mechanism. The command is from the mime-support package, which I think is installed by default on both Debian and Ubuntu (and anyway it's in many packages' dependencies, so it's probably installed already).

On many systems, you can use xdg-open myfile from the xdg-utils suite. This opens the file in the application that's associated to the file type through the Freedesktop mechanism. The Ubuntu package is xdg-utils, also probably installed already.

Gilles 'SO- stop being evil'

Posted 2010-12-10T16:19:13.447

Reputation: 58 319

Yeah, xdg-open works fine, I was only trying to see if what was possible on Windows could be transposed to Linux ;-) I struggled a bit with binfmt_misc, but couldn't get it to work in a seimple way, i.e.: echo ':txt_file:E:*.txt:::/usr/bin/gedit::' > /proc/sys/fs/binfmt_misc/register but this doesn't work on my machine... I guess it wasn't designed to do such things in the beginning. – kebs – 2010-12-14T13:46:40.043

And by the way, do you guys know if there is any difference between "see" and "xdg-open" ? They both seem to use the system's mime database... – kebs – 2010-12-14T13:51:35.253

1@kebs: see uses exactly the system's MIME database (including ~/.mailcap. I think xdg-open uses a completely different FreeDesktop-specified database, but Debian and Ubuntu packages tend to populate both these databases. – Gilles 'SO- stop being evil' – 2010-12-14T22:15:53.873

1

You could use gnome-open for that. Works pretty well for me.

DerMike

Posted 2010-12-10T16:19:13.447

Reputation: 779