系统如何在需要时调用便携式应用程序(例如文件关联)?
Linux 中有一些可移植应用程序的实现,但似乎所有 Mac OS X 应用程序都是可移植的。由于 Mac OS X 完全采用这种模型,我假设他们已经找到了解决这个问题的方法。
由于 Windows 通过将文件放在各处并更改注册表中的内容来“安装”应用程序,因此可以轻松地进行文件关联。但是,假设我刚刚下载了适用于 Mac OS X(或其他)的 MPlayer。我希望我的所有电影都能在 MPlayer 中打开。然后,我决定移动 MPlayer 的应用程序包(嘿,它是便携式的,对吧?)。协会会破裂吗?或者 OS X 上根本就不是这样的?
如何在 Linux 中实现便携式应用程序?它应该类似于 OS X 的模型吗?我知道这是一个非常开放式的问题,但任何建议都会受到赞赏。
There are a few implementations of portable apps in Linux, but it seems that all Mac OS X apps are portable. Since Mac OS X completely embraces this model, I'm assuming they already have a solution to this problem.
Since Windows "installs" apps by putting files all over the place, and changing things in the registry, file associations can be made easily. But, let's say I just downloaded MPlayer for Mac OS X (or whatever). I want all my movies to open in MPlayer. Then, I decide to move MPlayer's app bundle (hey, it's portable, right?). Will the association break? Or is that not how it's done at all on OS X?
How would one implement portable apps in Linux? Should it be similar to OS X's model? I know this is a very open-ended question, but any suggestions are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OS X 的启动服务数据库以多种方式跟踪文档绑定,通常它会尽力匹配应用程序,即使您已经移动了它。
您可以运行
lsregister -dump
(lsregister
是/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister
)以查看启动服务数据库对绑定的说明。例如,如果我绑定文本文件以使用 TextWrangler 打开,我会看到:public.plain-text
是 统一类型标识符(映射到一个或多个文件扩展名、MIME 类型等,并且可能有子类型)表示纯文本,com.barebones.textwrangler
是TextWrangler的bundle ID。我不知道有任何 Linux 标准对于文档绑定来说如此强大 - 要执行类似 Mac 的操作,首先需要有一个标准方法来识别应用程序,无论其位置或名称如何(如 Java 包之类) /reverse-DNS 方法(Mac 上),然后是类型映射和绑定的注册表,后面是足够有用的桌面环境,以及安装应用程序时注册应用程序的某种方法。
您不一定需要单独的文件(例如 Mac 应用程序包中的
Info.plist
)来存储此信息;即使在 Mac OS X 上,您也可以将信息嵌入到启动服务索引的二进制部分中(请注意,这不是单独的“分叉”或扩展属性;这就像将调试信息嵌入到可执行文件中)。因此,也许可以嵌入.desktop
文件的某些衍生文件。另一方面,您需要一种识别内容的方法。理想情况下,您甚至可以像file(1)
命令一样进行内容嗅探来识别文档类型;经典的 Mac 操作系统通过翻译管理器(允许注册从一种格式到另一种格式的转换器以及嗅探器)。UTI 和翻译管理器处理剪贴板并拖动和拖动将内容和文件拖放到磁盘上;当您这样做时,统一这些格式表示非常有用。
OS X's Launch Services database keeps track of document bindings in several ways—generally it does its best to try to match an application even if you've moved it.
You can run
lsregister -dump
(lsregister
is/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister
) to see what the Launch Services database says about a binding. For example, if I bind text files to open with TextWrangler, I see:public.plain-text
is a Uniform Type Identifier (which maps to one or more file extensions, MIME types, etc., and may have subtypes) representing plain text, andcom.barebones.textwrangler
is the bundle ID of TextWrangler.I'm not aware of any Linux standard as robust as this for document binding—to do something like the Mac, first there'd need to be a standard method for identifying applications regardless of their location or name (like the Java package-like/reverse-DNS method on the Mac), then a registry for type mappings and bindings that was followed by enough desktop environments to be useful, and some way of registering applications as they're installed.
You don't necessarily need separate files, like
Info.plist
in Mac application bundles, to store this information; even on Mac OS X you can embed information into a binary section which Launch Services indexes just fine (note that this is not a separate "fork" or extended attribute; it's like embedding debug information in an executable). So perhaps some derivative of the.desktop
files could be embedded. On the other end, you'd need a way of recognizing content. Ideally you'd even be able to do content sniffing like thefile(1)
command to identify a document type; classic Mac OS did this with the Translation Manager (which permitted registration of converters from one format to another, as well as sniffers).UTIs and the Translation Manager handle(d) clipboard and drag & drop content as well as files on disk; unifying these format representations is pretty useful while you're at it.
每个文件浏览器(例如 Nautilus、Konqueror)都必须配置为使用自己的文件关联。幸运的是,免费桌面项目一直致力于标准化文件关联(以及许多其他事情)。根据共享MIME数据库描述,尚未编写正式规范,但格式几乎是标准化的。
免费桌面项目还使用
.desktop
文件来提供“可移植性”(也许您应该使用另一个词来表示......也许“可移动”?)。如果将可执行文件移至PATH
之外,则可以更新.desktop
以指向正确的位置。基本上,Linux 社区正在进行大量工作,以更加用户友好和开发人员友好(即标准化)的方式来实现这些目标。但事情还没有完成。
Each file browser (e.g. Nautilus, Konqueror) would have to be configured to use its own file associations. Fortunately, the Free Desktop project has been working on standardizing file associations (among many other things). According to the shared MIME database description, no formal specification has been written yet, but the format is pretty much standardized.
The Free Desktop project also uses
.desktop
files to provide "portability" (maybe you should use another word for this... perhaps "movable"?). If you move the executable outside ofPATH
, you can update the.desktop
to point to the correct location.Basically, there is a lot of ongoing work in the Linux community moving towards more user-friendly and developer-friendly (i.e. standardized) ways of accomplishing these goals. But things are not done yet.