views:

210

answers:

3

On Gnome/KDE you can select in which application you want to open file (Right click on file -> Open With -> Other). Is it possible open file that way, but from console?

For example: you print " file.ext" and instead of opening in concrete application, there are that application selection window forced and then users chooses - starts selected program.

I tried to figure out that myself, but not found anything like that.

"edit file.ext" doesn't fits my needs, because it starts preferred application and you cannot choose which. And also on my desktop it says: "Error: no "edit" mailcap rules found for type "image/jpeg"

So, am I able to forse that "open with" window from console? If yes, can you say how? Both on windows and mac you can do such things.

//edit at 2009-02-10 14:17

Thank you very much for answers. Command will be used in program code, so unfortunately probably I would not be able to make some extra bash scripts.

+1  A: 

For GNOME:

gnome-open <file>

For KDE:

kfmclient exec <file>

These commands should open up the <file> in the preferred application in GNOME or KDE respectively, although I don't have an installation of either to test on.

David Grant
Oh, great. One of problems solved.Still, sometimes, starting preferred application not always works. For example, if you want to edit "edit.jpg" you brobably would want to start it in gimp or so, but gnome-open will start viewer.Do you know how to solve it?
Arturas
Well, I used your solution, so I mark this answer as "accepted".
Arturas
A: 

Traditionally, on Unix systens (and therefore Linux, too), you start applications from the console (and not from a UI). The command line (or console) expects you to enter the name of the application and then the filename (plus some options).

This allows to use applications (or commands) in shell scripts.

On Windows, there is no real console (the DOS box is just a reminiscence of the dark ages of MS DOS). So the MS developers came up with the idea to have the OS treat anything as a command. If it's not a real command or application, the OS will determine the file type (by extension on Windows and by some header information on Mac). For each file type, there will be an associated application in a look up table.

This is why on Windows, it appears that you can enter the name of a file on the console and you will get the application to edit that file.

If you want a quick way to fix this in the Unix console, create a script called "open" or "o" and use the file command with the option --mime to identify the file type. You can then use a case statement to launch your favorite editor.

As for the error about "mailcap rules": There is a file called "mailcap" on Unix where you can define abstract "commands" (open, edit, view, print) for file types. See the mailcap man page.

Aaron Digulla
Thank you for info.I am very curious why on linux there are no easy solution, because as I know on Mac there simply is "open" executable, which you can call if you want to force "application selection window". For example:open some_file.jpgIs there really no solution like that one on mac?
Arturas
Debian seems to have something in the mime package; but the main reason is that Unix users know all their applications and they are used to type "command options", so there was never a need to have something more comfortable. Also, how could you send options to the app?
Aaron Digulla
Script will be executed in client and I don't know that software each of them are using. That is main problem.Could you explain your last question? I didn't get it.
Arturas
The original question was about Java, but it seems, that there are no other way to do what, only use exec() function (you can write any console command in it). I transformed it into general question because I didn't want to limit it only to Java community.
Arturas
There is no default way to do this; you have to write a script and then call that script with the filename as a parameter. Or you must teach your Java app each file type (and the application). Sorry.
Aaron Digulla
As to "how could you send options to the app?": most unix command take options in addition to the filenames they process. How could you send the options to the application when starting it with "filename.ext"? This is not an issue when you click on an icon but it is on the command line.
Aaron Digulla
+1  A: 

Take a look at man run-mailcap, you can change or add selected applications for each mimetype modifying the /etc/mailcap, ~/.mailcap files and some others.

Jaime Soriano