是否可以从Linux控制台调用应用程序选择窗口(右键->打开方式->其他)?

发布于 2024-07-13 14:25:44 字数 484 浏览 4 评论 0原文

在 Gnome/KDE 上,您可以选择要在哪个应用程序中打开文件(右键单击文件 -> 打开方式 -> 其他)。 是否可以通过这种方式打开文件,但是从控制台?

例如:您打印“file.ext”,而不是在具体应用程序中打开,而是强制显示应用程序选择窗口,然后用户选择 - 启动选定的程序。

我试图自己弄清楚这一点,但没有发现类似的东西。

“edit file.ext”不符合我的需求,因为它启动首选应用程序,您无法选择哪个。 我的桌面上还写着: “错误:没有找到类型“image/jpeg”的“编辑”mailcap 规则

那么,我可以从控制台强制打开“打开方式”窗口吗?如果可以,您能说出具体方法吗? 在 windows 和 mac 上你都可以做这样的事情。

//编辑于2009-02-10 14:17

非常感谢您的解答。 命令将在程序代码中使用,因此不幸的是我可能无法制作一些额外的 bash 脚本。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海拔太高太耀眼 2024-07-20 14:25:44

对于 GNOME:

gnome-open <file>

对于 KDE:

kfmclient exec <file>

这些命令应该分别在 GNOME 或 KDE 中的首选应用程序中打开 ,尽管我没有安装进行测试。

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.

酒几许 2024-07-20 14:25:44

看一下 man run-mailcap,您可以为每个 mimetype 修改或添加选定的应用程序,修改 /etc/mailcap~/.mailcap 文件和其他一些。

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.

病女 2024-07-20 14:25:44

传统上,在 Unix 系统(因此 Linux 也是如此)上,您从控制台(而不是从 UI)启动应用程序。 命令行(或控制台)要求您输入应用程序的名称,然后输入文件名(加上一些选项)。

这允许在 shell 脚本中使用应用程序(或命令)。

在 Windows 上,没有真正的控制台(DOS 框只是 MS DOS 黑暗时代的回忆)。 因此,MS 开发人员提出了让操作系统将任何内容视为命令的想法。 如果它不是真正的命令或应用程序,操作系统将确定文件类型(在 Windows 上通过扩展名,在 Mac 上通过一些标头信息)。 对于每种文件类型,查找表中都会有一个关联的应用程序。

这就是为什么在 Windows 上,您似乎可以在控制台上输入文件名,然后您将获得应用程序来编辑该文件。

如果您想在 Unix 控制台中快速解决此问题,请创建一个名为“open”或“o”的脚本,并使用带有选项 --mime 的 file 命令来识别文件类型。 然后,您可以使用 case 语句 启动您喜欢的编辑器。

至于关于“mailcap规则”的错误:Unix上有一个名为“mailcap”的文件,您可以在其中定义文件类型的抽象“命令”(打开、编辑、查看、打印)。 请参阅 mailcap 手册页

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文