Icons for custom files (with document file extensions)


#1

Hi,

I'm trying to make the custom file types I have associated with my applications display an icon (on OS X).

I have tried this in the introjucer:

1.  Adding my Icon as a png to the files in the project

2. Selecting that icon for 'Icon (small)' and 'Icon (large)' in the XCode project settings in Introjucer [the icon works for the app itself]

3. Setting my document file extension in the relevant box in the XCode project settings

 

I can see in XCode when the project is generated it says "Document Types(1)" and when i expand this it shows my document file extension.

However, under the icon it says "no image specified".

 

Any ideas what I'm doing wrong?

 

Thanks in advance!

Adam


#2

Does no-one know how to do this?

 

I have read all the other forum posts on this, e.g.

 

this one: http://www.juce.com/forum/topic/how-set-file-icon-mac

or this one: http://www.juce.com/forum/topic/icon-custom-file-types

 

They all indicate that the Introjucer will sort it out if you put the file extension in the list. I have put in my list of file extentions and it isn't working, with the effects described in my first post. Anyone who can help?

 

Thanks,

 

Adam


#3

A further update: I have noticed that a second file type of mine DOES show the icon. For the main one that i am interested in, I have tried renaming it, changing the order in the list, and that one will never show the icon type. I'm sure i'm doing something horribly stupid but I can't tell as I'm not sure what I'm supposed to do...

 


#4

It doesn't sound like you're doing anything wrong, but I've always found that it's fairly random as to whether OSX picks up the document associations from your app file and starts using them or not.

There may be a way to force the OS to refresh its document type associations, but I don't know what it would be.

(I think sometimes the confusion comes if you have multiple copies of different versions of your app, and some of them have different file associations. Once OSX has registered one instance of the app, then making it change to look at a different one can be hit-and-miss)


#5

Can’t you just set the icon when you save the file?

Rail


#6

Hi all,

I'm bumping this again because I think something isn't working correctly and I have some info on what it might be.

 

Try this...

1) Use the Introjucer to select file icons and some document extensions

2) Save and open the project in XCode

3) Look at [Your-Project-Name]->Info->Document Types

4) You should see your file types listed, but, for me at least, under 'Icon' it says 'None'

5) If I click on the dropdown and choose my icon, then suddenly everything works and my document types have the right icon

 

I did a diff on the plist file produced for my app for both the situation when I don't select the icon in the list, and the situation where I do. The only key that is added is:

<key>CFBundleTypeIconFile</key>
<string>Icon</string>

which is in the dict associated with the extension.

 

If this is just happening to me, then it isn't clear what I'm doing to trigger it. Any thoughts?

 

UPDATE: If I change:

addPlistDictionaryKey (dict2, "CFBundleTypeName", ex);
addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor");
addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");

to


addPlistDictionaryKey (dict2, "CFBundleTypeName", ex); 
addPlistDictionaryKey (dict2, "CFBundleTypeRole", "Editor"); 
addPlistDictionaryKey (dict2, "CFBundleTypeIconFile", "Icon"); 
addPlistDictionaryKey (dict2, "NSPersistentStoreTypeKey", "XML");

in the Introjucer project file jucer_ProjectExport_XCode.h then it works... (this effectively adds the correct line in the plist to make the icon file associated with the file types)

 

Thanks,

 

Adam


#7

Thanks very much for the info! I'll fix this shortly.


#8

Great, thank you! :)