Page 1 of 1

How to copy Icon file to a folder?

Posted: Mon Sep 05, 2016 5:26 pm
by Wolfram
Can someone show me how to copy a .icns to a folder?

I want to paste a special Icon on every folder which is created by my program.

Re: How to copy Icon file to a folder?

Posted: Mon Sep 05, 2016 6:09 pm
by wilbert
Do you really want to copy the file or do you want to set an icon for a directory ?
If you want to set an icon, take a look at the setIcon:forFile:options: method from the NSWorkspace class.

Re: How to copy Icon file to a folder?

Posted: Mon Sep 05, 2016 6:19 pm
by Wolfram
But this use just one image and an .icns file includes different sizes.

Do you have any other idea?

Re: How to copy Icon file to a folder?

Posted: Mon Sep 05, 2016 7:10 pm
by wilbert
Wolfram wrote:But this use just one image and an .icns file includes different sizes.
Are you sure ? It looks pretty good to me

Code: Select all

Workspace = CocoaMessage(0, 0, "NSWorkspace sharedWorkspace")
Icon = CocoaMessage(0, CocoaMessage(0, 0, "NSImage alloc"), "initWithContentsOfFile:$", @"icon.icns")
CocoaMessage(0, Workspace, "setIcon:", Icon, "forFile:$", @"MyFolder", "options:", 0)
CocoaMessage(0, Icon, "release")

Re: How to copy Icon file to a folder?

Posted: Mon Sep 05, 2016 7:35 pm
by Wolfram
Yes, I'm sure.
For example: get info of the Preview.app and copy the icon shown on the top of the window. Open the Preview.app and press CMD + N.
You will see the icon in different sizes and resolutions (for retina and normal).


And that's exactly the code I need ;-)
Thanks!

Re: How to copy Icon file to a folder?

Posted: Mon Sep 05, 2016 7:43 pm
by wilbert
Works exactly the same when I try it (OSX 10.11.6).
If I copy the icon that my code has set for a folder and press Cmd + N in the preview app, it shows in all different sizes.
Are you sure your .icns file contains multiple images with different sizes ?