Get Preferred Application Icon URL for a given file

  • Hi All,
          I've a specific requirement to get preferred application Icon for a
    file.

          I've gone thru the Cocoa API and found that NSWorkspace is able to
    get the icon as NSImage but i need to get icon URL , so that my Webkit HTML
    Page img tag -- can show that image.

          I feel this should be possible may be using some other API or lower
    level API's.

          Can any one provide some pointers to solve this problem.

          Please help me to solve this. Thanks in Advance.

    -JanakiRam.
  • On Nov 11, 2007, at 9:23 AM, JanakiRam wrote:

    > Hi All,
    > I've a specific requirement to get preferred application Icon
    > for a
    > file.
    >
    > I've gone thru the Cocoa API and found that NSWorkspace is
    > able to
    > get the icon as NSImage but i need to get icon URL , so that my
    > Webkit HTML
    > Page img tag -- can show that image.

    You assume such a thing is possible, but there are several problems:

    1) For classic or CFM style apps, the icon could still be part of the
    resource fork for the application.  There is thus only a URL for the
    file, not the specific icon within that file.

    2) For other apps, the icons (at different sizes) are stored in
    an .icns file in the thing.  I don't believe that WebKit is able to
    display an icns file (since, among other things, it would have to pick
    which size you really wanted, which could easily end up with blocky
    images or blurry ones).

    3) Assuming that LaunchServices keeps each icon as a separate file
    (i.e. with a one to one mapping between icon and URL) in some internal
    cache is either wrong or subject to change, undocumented, unsupported,
    etc...  You can't even assume LaunchServices even keeps a cache of
    icons like the old desktop database did under Classic.

    >
    >
    > I feel this should be possible may be using some other API or
    > lower
    > level API's.
    >
    > Can any one provide some pointers to solve this problem.

    The best thing to do is to provide a custom "file-icon" protocol (or
    "pseudo-CGI" magic URL) that you implement in your program which
    fetches the icon at an appropriate size, and then returns the PNG or
    TIFF representation.  See NSURLProtocol (or the various "load request"
    related delegate methods for WebViews). This approach is definitely
    doable, though...

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium | prime : build, mutate, evolve, animate : the next
    generation of fractal art
  • NSWorkSpace is some how getting the preferred application image/icon ,
    constructing the NSImage object.
      Any idea's on how Apple guys did it ?

      I also heard that GNU Nextstep is the open source version of Earlier
    Cocoa Frameworks. Can i be able to download the sources ?

    On 11/11/07, glenn andreas <gandreas...> wrote:
    >
    >
    > On Nov 11, 2007, at 9:23 AM, JanakiRam wrote:
    >
    >> Hi All,
    >> I've a specific requirement to get preferred application Icon
    >> for a
    >> file.
    >>
    >> I've gone thru the Cocoa API and found that NSWorkspace is
    >> able to
    >> get the icon as NSImage but i need to get icon URL , so that my
    >> Webkit HTML
    >> Page img tag -- can show that image.
    >
    > You assume such a thing is possible, but there are several problems:
    >
    > 1) For classic or CFM style apps, the icon could still be part of the
    > resource fork for the application.  There is thus only a URL for the
    > file, not the specific icon within that file.
    >
    > 2) For other apps, the icons (at different sizes) are stored in
    > an .icns file in the thing.  I don't believe that WebKit is able to
    > display an icns file (since, among other things, it would have to pick
    > which size you really wanted, which could easily end up with blocky
    > images or blurry ones).
    >
    > 3) Assuming that LaunchServices keeps each icon as a separate file
    > (i.e. with a one to one mapping between icon and URL) in some internal
    > cache is either wrong or subject to change, undocumented, unsupported,
    > etc...  You can't even assume LaunchServices even keeps a cache of
    > icons like the old desktop database did under Classic.
    >
    >>
    >>
    >> I feel this should be possible may be using some other API or
    >> lower
    >> level API's.
    >>
    >> Can any one provide some pointers to solve this problem.
    >
    > The best thing to do is to provide a custom "file-icon" protocol (or
    > "pseudo-CGI" magic URL) that you implement in your program which
    > fetches the icon at an appropriate size, and then returns the PNG or
    > TIFF representation.  See NSURLProtocol (or the various "load request"
    > related delegate methods for WebViews). This approach is definitely
    > doable, though...
    >
    >
    >
    > Glenn Andreas                      <gandreas...>
    > <http://www.gandreas.com/> wicked fun!
    > quadrium | prime : build, mutate, evolve, animate : the next
    > generation of fractal art
    >
    >
    >
    >
  • At 08:38 -0800 11/11/2007, <cocoa-dev-request...> wrote:
    > From: JanakiRam <johnyatforums...>
    > References: <3f7852640711110723v7b5f006cq34b0df45c4e9a198...>
    > <85C95AF1-ECF0-47F7-8A88-CF45A0863449...>
    > In-Reply-To: <85C95AF1-ECF0-47F7-8A88-CF45A0863449...>
    > Date: Sun, 11 Nov 2007 21:39:54 +0530
    > Message-ID: <3f7852640711110809i75898ec4l4d0eade2255fe5ff...>
    >
    > NSWorkSpace is some how getting the preferred application image/icon ,
    > constructing the NSImage object.
    > Any idea's on how Apple guys did it ?

    I believe internally they call GetIconRefFromFileInfo() and then pass the iconRef to the new -[NSImage initWithIconRef:] API.

    The iconRef you get from GetIconRefFromFileInfo() may not correspond to a specific image file on disk. Besides what Glenn Andreas already mentioned in a previous reply, if the file has a Finder badge, or is an alias, you get a new composited image which doesn't exist anywhere.

    I seem to recall that WebKit supports some new syntax for doing in-line images - meaning TIFF data (or whatever) specified inside the <img /> tag - so you may want to investigate that instead.

    --
    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
  • On 11 Nov 2007, at 17:11, Rainer Brockerhoff wrote:

    > At 08:38 -0800 11/11/2007, <cocoa-dev-request...> wrote:
    >> From: JanakiRam <johnyatforums...>
    >> References:
    >> <3f7852640711110723v7b5f006cq34b0df45c4e9a198...>
    >> <85C95AF1-ECF0-47F7-8A88-CF45A0863449...>
    >> In-Reply-To: <85C95AF1-ECF0-47F7-8A88-CF45A0863449...>
    >> Date: Sun, 11 Nov 2007 21:39:54 +0530
    >> Message-ID:
    >> <3f7852640711110809i75898ec4l4d0eade2255fe5ff...>
    >>
    >> NSWorkSpace is some how getting the preferred application image/
    >> icon ,
    >> constructing the NSImage object.
    >> Any idea's on how Apple guys did it ?
    >
    > I believe internally they call GetIconRefFromFileInfo() and then
    > pass the iconRef to the new -[NSImage initWithIconRef:] API.
    >
    > The iconRef you get from GetIconRefFromFileInfo() may not
    > correspond to a specific image file on disk. Besides what Glenn
    > Andreas already mentioned in a previous reply, if the file has a
    > Finder badge, or is an alias, you get a new composited image which
    > doesn't exist anywhere.
    >
    > I seem to recall that WebKit supports some new syntax for doing in-
    > line images - meaning TIFF data (or whatever) specified inside the
    > <img /> tag - so you may want to investigate that instead.

    Exactly, the NSImage does not necessarily have to exist on disk. You
    could either create data: URLs for WebKit to handle or write out the
    image to disk yourself in a temporary location.
    >
    > --
    > 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
previous month november 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    
Go to today