Determine whether a file has a custom icon

  • Hi there,

    Can anyone help me determine whether a file or folder has a custom
    icon? For example, I'd like to know whether the Finder would display
    the default folder icon for a given folder, or some other icon.

    I know I can use +iconForFile in NSWorkspace to get an NSImage of the
    icon in question, but I don't know how to tell whether this is a
    default icon or a custom one.

    A previous proposed solution on this list was to use kHasCustomIcon in
    the Finder flags. This is rarely set and doesn't do the trick.

    Thanks,
    Adrian
  • On Dec 3, 2007, at 5:07 PM, Adrian Ross wrote:

    > Hi there,
    >
    > Can anyone help me determine whether a file or folder has a custom
    > icon? For example, I'd like to know whether the Finder would display
    > the default folder icon for a given folder, or some other icon.
    >
    > I know I can use +iconForFile in NSWorkspace to get an NSImage of
    > the icon in question, but I don't know how to tell whether this is a
    > default icon or a custom one.
    >
    > A previous proposed solution on this list was to use kHasCustomIcon
    > in the Finder flags. This is rarely set and doesn't do the trick.

    I think you'll have to deal with checking for either the
    kHasCustomIcon bit being set or if the folder contains a file named
    Icon\r  (yes, 'Icon' followed by a CR, 0x0D).

    Such a file will store the custom icon data in either the resource
    fork or data fork.

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • At 15:49 -0800 03/12/2007, <cocoa-dev-request...> wrote:
    > From: Adrian Ross <onedrop...>
    > Date: Tue, 4 Dec 2007 12:07:54 +1300
    > Message-ID: <281BDBC1-3ADA-41F7-8F0E-FCCCA486E4CD...>
    >
    > Can anyone help me determine whether a file or folder has a custom icon? For example, I'd like to know whether the Finder would display the default folder icon for a given folder, or some other icon.
    >
    > I know I can use +iconForFile in NSWorkspace to get an NSImage of the icon in question, but I don't know how to tell whether this is a default icon or a custom one.
    >
    > A previous proposed solution on this list was to use kHasCustomIcon in the Finder flags. This is rarely set and doesn't do the trick.

    Depends on what sort of "custom icon" you mean. kHasCustomIcon is set when an actual custom icon was pasted into the Finder's Get Info window.

    Then there are the special icons displayed for certain folders, like /Applications, ~/Downloads and so forth. The generic way to test for these is to obtain a FSRef for the folder, then call GetIconRefFromFileInfo() on it. Then you can (for instance) get the IconRef for the generic folder by calling GetIconRefFromTypeInfo(kSystemIconsCreator,kGenericFolderIcon...) and compare if they're equal.

    HTH,
    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "In the affairs of others even fools are wise
    In their own business even sages err."
    Weblog: http://www.brockerhoff.net/bb/viewtopic.php
  • > Depends on what sort of "custom icon" you mean. kHasCustomIcon is
    > set when an actual custom icon was pasted into the Finder's Get Info
    > window.
    >
    > Then there are the special icons displayed for certain folders,
    > like /Applications, ~/Downloads and so forth. The generic way to
    > test for these is to obtain a FSRef for the folder, then call
    > GetIconRefFromFileInfo() on it. Then you can (for instance) get the
    > IconRef for the generic folder by calling
    > GetIconRefFromTypeInfo(kSystemIconsCreator,kGenericFolderIcon...)
    > and compare if they're equal.

    I'm interested in what the Finder displays rather than how the icon
    got there (custom icon, application icon etc) so your solution works
    well for me.
  • No need for FSRef IMHO - use NSWorkspace iconForFile and
    iconForFyleType !?

    Am Dec 5, 2007 um 12:34 AM schrieb Adrian Ross:

    >> Depends on what sort of "custom icon" you mean. kHasCustomIcon is
    >> set when an actual custom icon was pasted into the Finder's Get
    >> Info window.
    >>
    >> Then there are the special icons displayed for certain folders,
    >> like /Applications, ~/Downloads and so forth. The generic way to
    >> test for these is to obtain a FSRef for the folder, then call
    >> GetIconRefFromFileInfo() on it. Then you can (for instance) get the
    >> IconRef for the generic folder by calling
    >> GetIconRefFromTypeInfo(kSystemIconsCreator,kGenericFolderIcon...)
    >> and compare if they're equal.
    >
    > I'm interested in what the Finder displays rather than how the icon
    > got there (custom icon, application icon etc) so your solution works
    > well for me.
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today