Mac OS X文件关联有效,但文件图标未更改 [英] Mac OS X file association works, but file icon not changed

查看:671
本文介绍了Mac OS X文件关联有效,但文件图标未更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Qt 5.3.2开发了Mac应用程序.此应用程序处理具有特定扩展名的文件(让我们说.xyz).

I have developed a Mac application using Qt 5.3.2. This application handles files with specific extension (lets say .xyz).

我创建了一个名为XYZ.icns的图标文件,并将其添加到我的应用程序包资源文件夹(MyApp.app/Contents/Resources/XYZ.icns)中.

I have created an icon file named XYZ.icns and added it to my app bundle Resource folder (MyApp.app/Contents/Resources/XYZ.icns).

我还修改了捆绑软件的Info.plist文件,以设置文件关联.我添加了此条目:

I have also modified the bundle's Info.plist file in order to set the file association. I have added this entry:

<key>CFBundleDocumentTypes</key>
<array>
    <!-- Registered file accociation -->
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleTypeName</key>
        <string>XYZ</string>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>xyz</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>XYZ</string>
    </dict>
<array>

结果:文件关联有效(双击文件确实打开了我的应用程序),但是图标未被替换(仍显示空白文档图标).

The result: the file association worked (double clicking on the file does open my application) however, the icon has not been replaced (still displaying the blank document icon).

有什么我想念的吗?我查看了其他应用程序作为示例,似乎没有什么比我做的要多了.

Is there something that I missed? I looked at other applications for examples and there does not seem to be anything more than what I did.

编辑:我还做了一些测试. 我使用以下命令转储了启动服务数据:

EDIT: I did some more tests. I dumped the Launch service data with this command:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -dump

结果是,我可以找到包含图标信息的文件类型的声明:

In the result, I can find claims on file the file type including the icon information:

...

--------------------------------------------------------------------------------
Container mount state: mounted
bundle  id:            105396
    ...
    path:          /Applications/MyApp.app
    name:          MyApp
    ...
    --------------------------------------------------------
    claim   id:            27628
        name:          XYZ
        rank:          Default
        reqCaps:      
        roles:         Editor  
        flags:         relative-icon-path  doc-type  
        icon:          Contents/Resources/XYZ.icns
        bindings:      .xyz
--------------------------------------------------------------------------------
...

EDIT2 :经过一段时间,它终于可以独立工作了.一夜之间,安装了一个操作系统更新,我还必须关闭计算机(启动服务可能会自动刷新某些内容).我将问题更新为:在安装或修改应用程序时如何确保启动服务刷新关联的文件图标?

EDIT2: After some time, it finally got to work on its own. Overnight, there is an OS update that got installed and I also had to shutdown the computer (the Launch Service probably refreshed something on its own). I would update my question to : How to make sure Launch Service refreshes the associated file icons when an application is installed or modified?

推荐答案

我的理解是,某些(内置)操作会触发Launch Services刷新数据库.与运行PackageMaker安装程序一样,将一个新的.app捆绑包拖动到Applications文件夹中也是一个触发器.但是,Launch Services数据库中的内容和Finder显示的内容之间可能会断开连接(直到进行其他一些刷新/重新启动).

My understanding is certain (built-in) actions trigger Launch Services to refresh the database. Dragging a new .app bundle to an Applications folders is one trigger, as is running a PackageMaker installer. However there may be a disconnect between what's in the Launch Services database and what the Finder shows (until some other refresh/restart).

一些快速的Google搜索建议您可以从命令行强制进行重建:/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user

Some quick Google searching suggests you can force a rebuild from the command line: /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user

但是,由于有内置触发器,因此不需要此步骤,因此除非您能清楚地确定为什么内置触发器对您的应用程序失败的原因,否则我会犹豫使用它.而且,如果问题出在Finder的图标缓存中,则可能也无济于事.

However, this step should not be necessary due to the built-in triggers, so I would be hesitant to use it unless you can clearly identify why the built-in triggers fail for your application. And if the problem is the Finder's icon cache, this may not help either.

这篇关于Mac OS X文件关联有效,但文件图标未更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆