Associating a file extension with my application

不问归期 提交于 2019-12-06 04:51:44

问题


I know how to manually associate a specific file or generic extension with a particular OS X application. (Get Info > Open with > Other…)

I know how, in OS X, to drag-and-drop a file with an extension onto an 'unsupported' application. (Hold down command-option when dragging over the application)

As the author of an OS X application, how can I specify that my application knows how to open a particular file extension?

  • I want my users not to need to use command-option for drag-and-drop.
  • I want my users to see my application listed under "Recommended Applications" instead of "All Applications" when picking an app to open my extensions.
  • Ideally, I want my users to see files with my (unique, not-already-associated) extension magically show the correct icon and open with my application as soon as the .app is dragged into the Applications folder.

I have seen "MacOSX - File extension associate with application - Programatically", but I do not want to have to have users run an installer or shell script after installation.


回答1:


To declare its support for file types, your app must include the CFBundleDocumentTypes key in its Info.plist

Then implement

- application:openFile: (for single file drag-drop)
or
- application:openFiles: (multiple files drag-drop)

Have a look at Complete the Information Property List section in Document-Based App Programming Guide for Mac



来源:https://stackoverflow.com/questions/19693311/associating-a-file-extension-with-my-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!