Mac OS X - 将应用程序与文件类型图标相关联

时间:2009-10-31 19:55:07

标签: macos

我想说明对于某种文件类型,该图标是由我的应用动态生成的。例如,照片在Finder中显示为缩略图 - 我希望.myapp文件在Finder中显示为特殊的每个文件生成的图标。我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

查看CFBundleTypeName,CFBundleTypeIconFile,LSItemContentTypes等的Apple文档... http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Documents/Concepts/DocTypePList.html

答案 1 :(得分:0)

我试图这样做。我发现有用的解决方案是为应用程序注册自己的文件类型。为此,您需要在应用程序的info.plist中指定新密钥。指定CFBundleTypeName(您的文件类型)和CFBundleTypeExtensions(您的文件扩展名为mytxt)。要指定自定义图标,请使用CFBundleTypeIconFile文件名填充.icns。将.icns文件放在Resources中的.app内也很重要。

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>your_file_type</string>

        <key>CFBundleTypeExtensions</key>
        <array>
            <string>your_file_type</string>
        </array>

        <key>CFBundleTypeIconFile</key>
        <string>app.icns</string>

        <key>CFBundleTypeRole</key>
        <string>Viewer</string>

        <key>LSTypeIsPackage</key>
        <false />

        <key>NSPersistentStoreTypeKey</key>
        <string>Binary</string>
    </dict>
</array>
相关问题