Icon Overlay on Mac OSX

  • Hi,

    I'm a newbie in Cocoa framework, XCode and also Obj-C.
    I'm still struggling to create an icon overlay in finder like the one in
    that dropbox did.
    During my investigation about this I found that dropbox was using
    injection method to the finder code using mach_star
    (https://github.com/rentzsch/mach_star). you can find the discussion in
    here :
    http://stackoverflow.com/questions/1294335/how-to-write-os-x-finder-plugin.
    but there's no exact example and how-to, that makes it very difficult to
    implement.
    And also I found this discussion too, I don't know it's related or not :
    https://discussions.apple.com/thread/2536878?start=0&tstart=0.
    It also makes me confused, because I'm a newbie :D .

    I want to ask you guy's opinion about this issue.
    And if some of you guys have an experience with it, please share it with me.

    Thanks,

    Best Regards,
    Alfian
  • You might like to check out CTBadge - there are a couple of minor memory issues in the current release which will be picked up in Xcode's analyze function, but apart from that, it will probably point you in the right direction.

    http://blog.oofn.net/2006/01/08/badging-for-everyone/

    Regards

    Gideon

    On 09/07/2012, at 3:34 PM, Alfian Busyro <alfian.busyro...> wrote:

    > Hi,
    >
    > I'm a newbie in Cocoa framework, XCode and also Obj-C.
    > I'm still struggling to create an icon overlay in finder like the one in that dropbox did.
  • On Mon, Jul 9, 2012, at 02:34 PM, Alfian Busyro wrote:
    > I want to ask you guy's opinion about this issue.
    > And if some of you guys have an experience with it, please share it with
    > me.

    As said before, there is no supported way to do this. You should not
    attempt it. Discussion about methods of injecting code into the Finder,
    etc. are off-topic for this list.

    --Kyle Sluder
  • On Jul 9, 2012, at 12:34 AM, Alfian Busyro wrote:

    > I'm a newbie in Cocoa framework, XCode and also Obj-C.
    > I'm still struggling to create an icon overlay in finder like the one in that dropbox did.
    > During my investigation about this I found that dropbox was using injection method to the finder code using mach_star (). you can find the discussion in here : <A href="http://stackoverflow.com/questions/1294335/how-to-write-os-x-finder-plugin">http://stackoverflow.com/questions/1294335/how-to-write-os-x-finder-plugin.
    > but there's no exact example and how-to, that makes it very difficult to implement.
    > And also I found this discussion too, I don't know it's related or not :
    > https://discussions.apple.com/thread/2536878?start=0&tstart=0.
    > It also makes me confused, because I'm a newbie :D .
    >
    > I want to ask you guy's opinion about this issue.
    > And if some of you guys have an experience with it, please share it with me.

    Please don’t do this kind of stuff. The use of code injection is one of the reasons I refuse to use Dropbox on OS X. It’s ugly, it’s fragile, and it’s prone to cause weird behavior and instability issues.

    Charles
  • Hi Gideon,
    Thanks for your reply.

    I tried this CTBadge, and it gave me a custom application icon after I
    run it.
    So a little bit different with what I want to do though.
    Do you have any idea how to implement this to the finder , without
    injecting it like dropbox did.

    With Regards,

    Alfian

    On 12/07/18 14:45, Gideon King wrote:
    > You might like to check out CTBadge - there are a couple of minor
    > memory issues in the current release which will be picked up in
    > Xcode's analyze function, but apart from that, it will probably point
    > you in the right direction.
    >
    > http://blog.oofn.net/2006/01/08/badging-for-everyone/
    >
    >
    > Regards
    >
    > Gideon
    >
    >
    > On 09/07/2012, at 3:34 PM, Alfian Busyro <alfian.busyro...>
    > <mailto:<alfian.busyro...>> wrote:
    >
    >> Hi,
    >>
    >> I'm a newbie in Cocoa framework, XCode and also Obj-C.
    >> I'm still struggling to create an icon overlay in finder like the one
    >> in that dropbox did.
    >
  • Just like I thought, injecting code is not a good way to do this.
    So, is it impossible to do this without injecting code to Finder ?

    With Regards,

    Alfian

    On 12/07/18 15:18, Kyle Sluder wrote:
    > On Mon, Jul 9, 2012, at 02:34 PM, Alfian Busyro wrote:
    >> I want to ask you guy's opinion about this issue.
    >> And if some of you guys have an experience with it, please share it with
    >> me.
    > As said before, there is no supported way to do this. You should not
    > attempt it. Discussion about methods of injecting code into the Finder,
    > etc. are off-topic for this list.
    >
    > --Kyle Sluder
  • On 18.07.2012, at 12:37, Alfian Busyro wrote:
    > Just like I thought, injecting code is not a good way to do this.
    > So, is it impossible to do this without injecting code to Finder ?

    For what purpose do you need this? If you only need a small number of animation steps, you could just set up a different filename suffix for each step, specify a different icon (all in your Info.plist) and then rename the file whenever you need the next step. Would that work in your case?

    In the old days, one could use Icon Services calls to change the icon used for a particular file type, that might even save you the renaming, but Icon Services is probably considered "old" API these days, and I'm not sure if changes to icons in your app using Icon Services will still affect Finder. Anyway, it's worth a try.

    Finally, you could use a custom icon (the kind you get when you click on the icon in a file's "Get Info" window in Finder and paste a graphic there). But of course, if there is any chance that your files already have a custom icon because the user set one on it, your code would replace that icon, which isn't nice. But for a newly-downloaded file, you could probably do that. I think there might be a setIcon:forFile: (or something like that) method in NSFileManager or NSWorkspace for setting a custom icon on a file.

    Cheers,
    -- Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
    http://groups.yahoo.com/group/mac-gui-dev/
  • On Jul 18, 2012, at 3:37 AM, Alfian Busyro <alfian.busyro...> wrote:

    > Just like I thought, injecting code is not a good way to do this.
    > So, is it impossible to do this without injecting code to Finder ?

    Yes, it is impossible. The Finder is not meant to be extended/hacked and has no API for this. This is absolutely not something you should be attempting as a newbie project. Please think of something easier to do.

    —Jens
  • On Jul 8, 2012, at 10:34 PM, Alfian Busyro wrote:
    >
    >
    > I want to ask you guy's opinion about this issue.

    My opinion: No way on earth am I letting Dropbox near my system.

    > And if some of you guys have an experience with it, please share it with me.

    There are official ways to change the Dock icon - see [NSApplication dockTile] - and you can have some fun with that. That would be a cool newbie project; I think there's even a sample app for it.
  • On 18.07.2012, at 12:37, Alfian Busyro wrote:
    > Just like I thought, injecting code is not a good way to do this.
    > So, is it impossible to do this without injecting code to Finder ?

    BTW -- just because nobody has mentioned it yet: You can also take the approach many other applications use: Create your own window, with your own list of files, and show whatever information you wanted to show in an overlay on Finder's icon. You can ask NSWorkspace for the icon you should show for a file, and then display that in one column of your NSTableView, for example. And NSWorkspace can also open a file just like Finder would do. And you can ask NSFileManager for the list of files in a particular folder. So essentially you'd be building a (very limited and much simpler) mini-Finder that only does what is needed for your application.

    Cheers,
    -- Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
    http://www.masters-of-the-void.com
  • Actually I'd like to do this.
    But I'm not the man who made the specification,
    and my superior want it in the app.

    Btw, thanks for all replies.

    Regards,
    Alfian

    On 12/07/21 2:28, Uli Kusterer wrote:
    > On 18.07.2012, at 12:37, Alfian Busyro wrote:
    >> Just like I thought, injecting code is not a good way to do this.
    >> So, is it impossible to do this without injecting code to Finder ?
    > BTW -- just because nobody has mentioned it yet: You can also take the approach many other applications use: Create your own window, with your own list of files, and show whatever information you wanted to show in an overlay on Finder's icon. You can ask NSWorkspace for the icon you should show for a file, and then display that in one column of your NSTableView, for example. And NSWorkspace can also open a file just like Finder would do. And you can ask NSFileManager for the list of files in a particular folder. So essentially you'd be building a (very limited and much simpler) mini-Finder that only does what is needed for your application.
    >
    > Cheers,
    > -- Uli Kusterer
    > "The Witnesses of TeachText are everywhere..."
    > http://www.masters-of-the-void.com
    >
    >
    >
  • On Jul 22, 2012, at 11:02 PM, Alfian Busyro wrote:

    >> So essentially you'd be building a (very limited and much simpler) mini-Finder that only does what is needed for your application.

    We do this with our apps and it is a good approach.

    -koko
  • On Jul 18, 2012, at 4:42 AM, Alfian Busyro <alfian.busyro...> wrote:

    > Hi Gideon,
    > Thanks for your reply.
    >
    > I tried this CTBadge, and it gave me a custom application icon after I run it.
    > So a little bit different with what I want to do though.
    > Do you have any idea how to implement this to the finder , without injecting it like dropbox did.
    >
    > With Regards,
    >
    > Alfian

    Nope.

    Charles
  • On Jul 18, 2012, at 2:42 AM, Alfian Busyro <alfian.busyro...> wrote:

    > I tried this CTBadge, and it gave me a custom application icon after I run it.
    > So a little bit different with what I want to do though.
    > Do you have any idea how to implement this to the finder , without injecting it like dropbox did.

    Set custom icons for the files? (I have no idea how custom file icons are done nowadays, though. They used to be stored in the resource fork, but that's been deprecated for a decade now. Maybe they're in extended file attributes?)

    —Jens
  • On Aug 2, 2012, at 12:47 AM, Jens Alfke <jens...> wrote:

    > On Jul 18, 2012, at 2:42 AM, Alfian Busyro <alfian.busyro...> wrote:
    >
    >> I tried this CTBadge, and it gave me a custom application icon after I run it.
    >> So a little bit different with what I want to do though.
    >> Do you have any idea how to implement this to the finder , without injecting it like dropbox did.
    >
    > Set custom icons for the files? (I have no idea how custom file icons are done nowadays, though. They used to be stored in the resource fork, but that's been deprecated for a decade now. Maybe they're in extended file attributes?)

    They're still in the resource fork (which itself is an extended file attribute).

    Charles
  • On 02.08.2012, at 07:47, Jens Alfke <jens...> wrote:
    > Set custom icons for the files? (I have no idea how custom file icons are done nowadays, though. They used to be stored in the resource fork, but that's been deprecated for a decade now. Maybe they're in extended file attributes?)

    NSWorkspace has a setIcon: forPath: method (or something like that) for this purpose. I think it was added around 10.6, might even be older. Or maybe it was NSFileManager. I mentioned it previously in this thread, not gonna look it up a second time.

    Cheers,
    -- Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
  • I believe setIcon updates the file modification date... (please check as I
    can't remember for sure)... which might go against what a file tracking
    system might be trying to do.

    i.e. will give false file modification updates because of setting the
    updated icons.

    If there is a way to do that without updating the file attributes, it would
    work perfectly...

    Kappa.

    On Thu, Aug 2, 2012 at 4:22 PM, Uli Kusterer
    <witness.of.teachtext...>wrote:

    > On 02.08.2012, at 07:47, Jens Alfke <jens...> wrote:
    >> Set custom icons for the files? (I have no idea how custom file icons
    > are done nowadays, though. They used to be stored in the resource fork, but
    > that's been deprecated for a decade now. Maybe they're in extended file
    > attributes?)
    >
    > NSWorkspace has a setIcon: forPath: method (or something like that) for
    > this purpose. I think it was added around 10.6, might even be older. Or
    > maybe it was NSFileManager. I mentioned it previously in this thread, not
    > gonna look it up a second time.
    >
    > Cheers,
    > -- Uli Kusterer
    > "The Witnesses of TeachText are everywhere..."
    >
  • On Aug 2, 2012, at 3:41 PM, KappA <rejekted...> wrote:

    > I believe setIcon updates the file modification date... (please check as I
    > can't remember for sure)... which might go against what a file tracking
    > system might be trying to do.
    >
    > i.e. will give false file modification updates because of setting the
    > updated icons.
    >
    > If there is a way to do that without updating the file attributes, it would
    > work perfectly...

    In addition to this, it will hose any custom icons that the user might have set on the files.

    Charles
  • I'll take a look of this.

    Thanks,
    Alfian

    On 12/08/02 14:55, Charles Srstka wrote:
    > On Aug 2, 2012, at 12:47 AM, Jens Alfke <jens...> wrote:
    >
    >> On Jul 18, 2012, at 2:42 AM, Alfian Busyro <alfian.busyro...> wrote:
    >>
    >>> I tried this CTBadge, and it gave me a custom application icon after I run it.
    >>> So a little bit different with what I want to do though.
    >>> Do you have any idea how to implement this to the finder , without injecting it like dropbox did.
    >> Set custom icons for the files? (I have no idea how custom file icons are done nowadays, though. They used to be stored in the resource fork, but that's been deprecated for a decade now. Maybe they're in extended file attributes?)
    > They're still in the resource fork (which itself is an extended file attribute).
    >
    > Charles
  • Which you guys mean I have to create the overlay to an Image it self
    then stick it to a file icon ?
    I'd try this before but nothing was changed. maybe I'll have try this
    once again.

    And for file attributes, can we use setAttributes:ofItemAtPath:error:
    from NSFileManager ?
    because there is NSFileModificationDate attributes for in this function.

    Regards,
    Alfian

    On 12/08/03 5:47, Charles Srstka wrote:
    > On Aug 2, 2012, at 3:41 PM, KappA <rejekted...> wrote:
    >
    >> I believe setIcon updates the file modification date... (please check as I
    >> can't remember for sure)... which might go against what a file tracking
    >> system might be trying to do.
    >>
    >> i.e. will give false file modification updates because of setting the
    >> updated icons.
    >>
    >> If there is a way to do that without updating the file attributes, it would
    >> work perfectly...
    > In addition to this, it will hose any custom icons that the user might have set on the files.
    >
    > Charles
  • Which you guys mean I have to create the overlay to an Image it self
    then stick it to a file icon ?
    I'd try this before but nothing was changed. maybe I'll have try this
    once again.

    And for file attributes, can we use setAttributes:ofItemAtPath:error:
    from NSFileManager ?
    because there is NSFileModificationDate attributes for in this function.

    Regards,
    Alfian

    On 12/08/03 5:47, Charles Srstka wrote:
    > On Aug 2, 2012, at 3:41 PM, KappA <rejekted...> wrote:
    >
    >> I believe setIcon updates the file modification date... (please check as I
    >> can't remember for sure)... which might go against what a file tracking
    >> system might be trying to do.
    >>
    >> i.e. will give false file modification updates because of setting the
    >> updated icons.
    >>
    >> If there is a way to do that without updating the file attributes, it would
    >> work perfectly...
    > In addition to this, it will hose any custom icons that the user might have set on the files.
    >
    > Charles
  • I have been playing around with that -

    get the attributes
    get the icon
    composite the overlay
    set the icon
    set the attributes

    When I print out the attributes before/after they match - now this only
    works for files that you have access to (it failed for a few files owned by
    root).

    I am not sure how this affects MD5 checksum, I am going to look into that
    next...

    On Thu, Aug 2, 2012 at 9:21 PM, Alfian Busyro <alfian.busyro...>wrote:

    > Which you guys mean I have to create the overlay to an Image it self then
    > stick it to a file icon ?
    > I'd try this before but nothing was changed. maybe I'll have try this once
    > again.
    >
    > And for file attributes, can we use setAttributes:ofItemAtPath:**error:
    > from NSFileManager ?
    > because there is NSFileModificationDate attributes for in this function.
    >
    > Regards,
    > Alfian
    >
    > On 12/08/03 5:47, Charles Srstka wrote:
    >
    >> On Aug 2, 2012, at 3:41 PM, KappA <rejekted...> wrote:
    >>
    >> I believe setIcon updates the file modification date... (please check as
    >>> I
    >>> can't remember for sure)... which might go against what a file tracking
    >>> system might be trying to do.
    >>>
    >>> i.e. will give false file modification updates because of setting the
    >>> updated icons.
    >>>
    >>> If there is a way to do that without updating the file attributes, it
    >>> would
    >>> work perfectly...
    >>>
    >> In addition to this, it will hose any custom icons that the user might
    >> have set on the files.
    >>
    >> Charles
    >>
    >> ______________________________**_________________
    >>
    >> Cocoa-dev mailing list (<Cocoa-dev...>)
    >>
    >> Please do not post admin requests or moderator comments to the list.
    >> Contact the moderators at cocoa-dev-admins(at)lists.**apple.com<http://lists.apple.com>
    >>
    >> Help/Unsubscribe/Update your Subscription:
    >> https://lists.apple.com/**mailman/options/cocoa-dev/**
    >> <alfian.busyro...><https://lists.apple.com/mailman/options/cocoa-dev/<alfian.busyro...>.
    com
    >
    >>
    >> This email sent to <alfian.busyro...>
    >>
    >
    > ______________________________**_________________
    >
    > Cocoa-dev mailing list (<Cocoa-dev...>)
    >
    > Please do not post admin requests or moderator comments to the list.
    > Contact the moderators at cocoa-dev-admins(at)lists.**apple.com<http://lists.apple.com>
    >
    > Help/Unsubscribe/Update your Subscription:
    > <<A href="https://lists.apple.com/mailman/options/cocoa-dev/<rejekted...>">https://lists.apple.com/mailman/options/cocoa-dev/<rejekted...>>
    >
    > This email sent to <rejekted...>
    >
  • On Aug 2, 2012, at 6:54 PM, KappA <rejekted...> wrote:

    > get the attributes
    > get the icon
    > composite the overlay
    > set the icon
    > set the attributes

    This has an obvious race condition, but it should work most of the time. If you don't change the icon often, you should be OK.

    > I am not sure how this affects MD5 checksum, I am going to look into that next...

    It doesn't, because it doesn't affect the contents of the file. Unless you use a fancy checksum tool that incorporates all the extended-attribute metadata.

    It *is* going to affect the disk space used, though. Since a 512x512 32-bit icon is a megabyte in size, that means you may be adding 1MB per file you badge. That can add up. And it's not at all obvious to a user where that space went, or how to recover it. So I would avoid doing this to lots of files.

    It also slows down the Finder a bit since it has to open the file and read the icon instead of just looking it up from a cache based on the file-type. (This can be really painful when viewing that folder over AFP file sharing, in fact IIRC the Finder may turn off the display of custom icons on remote folders for this reason.)

    —Jens
  • On Aug 2, 2012, at 9:26 PM, Jens Alfke <jens...> wrote:

    > On Aug 2, 2012, at 6:54 PM, KappA <rejekted...> wrote:
    >
    >> get the attributes
    >> get the icon
    >> composite the overlay
    >> set the icon
    >> set the attributes
    >
    > This has an obvious race condition, but it should work most of the time. If you don't change the icon often, you should be OK.

    Again, except for the fact that you will overwrite any custom icons that the user has decided to put on the files.

    Charles
  • Thanks. Yeah this too seems a bit messy, as you also have to take the quick
    look preview into consideration. (when switching the various Finder views).

    On Thu, Aug 2, 2012 at 10:37 PM, Charles Srstka <cocoadev...>wrote:

    > On Aug 2, 2012, at 9:26 PM, Jens Alfke <jens...> wrote:
    >
    > On Aug 2, 2012, at 6:54 PM, KappA <rejekted...> wrote:
    >
    > get the attributes
    > get the icon
    > composite the overlay
    > set the icon
    > set the attributes
    >
    >
    > This has an obvious race condition, but it should work most of the time.
    > If you don't change the icon often, you should be OK.
    >
    >
    > Again, except for the fact that you will overwrite any custom icons that
    > the user has decided to put on the files.
    >
    > Charles
    >
    >
previous month july 2012 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