Mac OS X file association works, but file icon not changed
Asked Answered
F

1

9

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

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

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: 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?

Fig answered 29/1, 2015 at 19:17 Comment(8)
tekrevue.com/tip/…Heflin
Hi You found the Ans for this question?Jigger
@vijay se edit 2. It worked on its own but i dont know why.Fig
@Fig thanks for responding.. Please let me know what sizes of icons to place derJigger
@vijay I used "Icon Composer" to create an icon that includes all sizes (512x512, 256x256, 128x128, 32x32, 16x16) using pngs. If you have Xcode installed, you can retrieve the "Icon Composer" tool by going to "Xcode > Open Developer Tool > More Developer Tools" the downloading and installing the "Xcode > Open Developer Tool > More Developer Tools"Fig
@Fig I didn't found the "Icon Composer" in Developer tools may be apple will removed this.. thanks..Jigger
@vijay you can google it... you will find apple.stackexchange.com/questions/59561/… or #12437933Fig
I spent a long time with launch services as well only to find that a reboot fixed it. Generally the icons "just work" however there appears to be an scenario which prevents the icons from showing without a restart, most likely caused by a rare trial-and-error scenario that only developers would encounter.Equiangular
U
4

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).

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

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.

Unseat answered 20/11, 2015 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.