我想将我的 Mac OS X 应用程序的最后安装版本与某种类型的文件关联起来。 一些实验表明,info.plist 文件似乎是在启动应用程序时由操作系统读取和解释的,而不是在将应用程序包拖到磁盘时。 Apple 有关运行时的文档配置在这个主题上没有说太多。
有什么方法可以使用简单的 .dmg 映像作为安装介质,以确保系统将该特定文件类型与我新安装的应用程序关联起来,而无需先启动它 ?
我应该澄清,我希望在安装过程中自动完成此操作(我不希望我的用户必须自己执行此操作)。
I would like to associate the last installed version of my Mac OS X application with a certain type of file. A little experimentation shows that the info.plist file seems to be read and interpreted by the operating system when launching the application, not when dragging the application bundle to the disk. Apple's documentation on run-time configuration does not say much on that topic.
Is there any way, using a simple .dmg
image as installation medium, to make sure the system associates that particular file type with my newly installed app without having to launch it first?
I should clarify that I want this to be done automatically during the installation (I don't want my users to have to do it themselves).
发布评论
评论(3)
当用户将应用程序拖到应用程序文件夹中时,系统应自动将其注册到启动服务中。 请参阅应用程序注册。
When a user drags an application into the Applications folder, the system should register it with Launch Services automatically. See Application Registration in the Launch Services Guide.
尽管托尼的信息是正确的 - 也在此处进行了解释 - (将
MyApp.app
拖到< code>Applications 将使用Info.plist
xml 文件和设置文件关联中的信息自动注册启动服务),它并不能完全回答有关文件关联的问题。如果人们按照这些说明操作,他们将打开应用程序,但不会打开特定文件。
与其他平台相比,Mac 上的文件关联有点不同。 大多数平台,当
*.foo
注册到myapp
时,当双击MyFile.foo
时,它会按照以下方式分派一些内容:尽管您可以在 Mac 上的命令行上成功地使用此技术,但它无法通过 Finder 工作,也无法通过双击桌面上的关联文件来工作。
在这里提问和回答:
https://stackoverflow.com/a/19702342/3196753
有些人声称这种方法比
main()
中的文档打开文件处理方式保守,因为它“仅打开应用程序的一个实例”。 不管这个决定背后的原因是什么,从 C++ 的角度来看,它都使事情变得更加复杂。来自 qt.io:
在 C++ main() 执行之前处理 Mac OS X 文件打开事件
启动时未调用 AEInstallEventHandler 处理程序
Although Tony's information is correct -- also explained here -- (that dragging the
MyApp.app
toApplications
will register with Launch Services automatically using information fromInfo.plist
xml file and setup file associations), it doesn't fully answer the question about file association.If people follow these instructions, they'll have their application open, but no specific file opened.
File association is a bit different on Mac as when compared to other platforms. Most platforms, when
*.foo
is registered withmyapp
, whenMyFile.foo
is double-clicked, it dispatches something along the lines of:And although you're free to use this technique on command line on a Mac with success, it simply won't work through Finder and also won't work through double-clicking the associated file on the desktop.
Asked and answered here:
https://stackoverflow.com/a/19702342/3196753
Some claim is this approach is advantageous over conservative document-open-file-handling in
main()
because it "only opens one instance of the application". Regardless of the reasoning behind this decision, it further complicates matters from a C++ perspective.From qt.io:
Handling Mac OS X file open event BEFORE C++ main() executes
AEInstallEventHandler handler not being called on startup
您可以通过在要与应用程序关联的文件上键入 apple-I 来完成此操作,使用名为“打开方式...”的小框并选择您的应用程序。 您可以选中“更改全部...”下面的小框来对所有类似文件进行更改。
You can do that by typing apple-I on the file you want to associate the application with, use the little box called "Open with..." and select your app. You can check the little box below "Change All..." to make the change for all similar files.