My program for MacOS is creating the alias to another file and I want this alias to have some designated icon. How can I do it with Objective-C, preferably in Cocoa?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
NSWorkspace, which has a method for doing this:This will save the icon data to the file’s Resource Fork. These days Mac OS doesn’t use actual resource forks, so the image is stored in an HFS extended attribute named
com.apple.ResourceFork.Extended attributes are filesystem metadata attached to a file. You can see the extended attributes attached to a file using
xattrand related commands.Note that extended attributes are only guaranteed to be reliable on HFS+ file systems, if the file is located on a file server that doesn’t support file metadata or on an external drive with a non-HFS file system, the icon may not be written.