问题
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