Instance Method

setIcon:forFile:options:

Sets the icon for the file or directory at the specified path.

Declaration

- (BOOL)setIcon:(NSImage *)image forFile:(NSString *)fullPath options:(NSWorkspaceIconCreationOptions)options;

Parameters

image

The image to use as the icon for the file or directory.

fullPath

The full path of the file or directory.

options

The icon representations to generate from the image. You specify this value by combining the appropriate NSWorkspaceIconCreationOptions constants, using the C bitwise OR operator. Specify 0 if you want to generate icons in all available icon representation formats.

Return Value

YES if the icon was set; otherwise, NO.

Discussion

The image can be an arbitrary image, with or without transparency. This image is automatically scaled (as needed) to generate the icon representations. The file or folder must exist and be writable by the user.

This method uses the image to set an icon whose size is 512 by 512 pixels. If you specify the NSExclude10_4ElementsIconCreationOption option (not recommended), this method creates an icon that is compatible with the pre-OS X v10.3 Finder.

It is safe to call this method from any of your app’s threads, but you must call it from only one thread at a time.

See Also

Managing Icons

- iconForFile:

Returns an image containing the icon for the specified file.

- iconForFileType:

Returns an image containing the icon for files of the specified type.

- iconForFiles:

Returns an image containing the icon for the specified files.

NSWorkspaceIconCreationOptions

These constants describe the NSWorkspaceIconCreationOptions values used by setIcon:forFile:options:. You can combine these using the C bitwise OR operator.