How to copy Icon file to a folder?

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

How to copy Icon file to a folder?

Post 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.
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How to copy Icon file to a folder?

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Re: How to copy Icon file to a folder?

Post by Wolfram »

But this use just one image and an .icns file includes different sizes.

Do you have any other idea?
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How to copy Icon file to a folder?

Post 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")
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Re: How to copy Icon file to a folder?

Post 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!
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How to copy Icon file to a folder?

Post 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 ?
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply