Getting the custom icon of the dropped folder (if available)…

MacOS, but can be XPlatform.

I drop a folder above the folder (look at the screen shot below) in a project, and sometimes I wonder if I have dropped one. Of course, if I click in a PushButton, nothing happens (or an error message pops…) if there was nothing dropped, but I prefer a visual feedback.

In the screen shot, I had data in the ListBox/TextArea, so I dropped a folder… *

How can I do that without plugin ?

  • I may want to build for the other two platforms.
    ListBox is populated when I ask a list (click in a PushButton that compute a list);
    TextArea is populated with html text when the appropriate PushButton is hit.
    A third PushButton toogle the display from one Control to the other (cause they share the same location on screen).

There are a bunch of ways to get the icon from a file. Apple have at least 3 different functions.

Once you have a NSImage, you need to then create a Xojo picture from it, or convert all your existing code to use NSImages, as you want a potential x-plat solution, I suggest you look into converting a NSImage.

If you don’t want a plugin, the source code to what you want is included as part of the Ohanaware App Kit, but that is a paid solution.

I also have a Xojo Feedback for being able to create a Xojo picture from a NSImage, if you find it and add your vote to it, it will help make part of the process more integrated.

Thank you Sam.

I was trying to use the Icon( or <?>) invisible file (the custom icon) who in fact is an icns file (I think (1)), but the Finder refuse to allow me to use it (it says it is in use).

Having a good idea is one thing; being able to implement it is another story.

(1) I was not able to open it, so… Copy it, set it to Visible is… “easy”, but I get stuck in the mud (and now I have to clean my shoes).

I have a (lame) solution:

add the said icon in the form of a png file in the concerned folder (s) and search for this file when the folder is dropped …

This project will end like a gas factory with all these workarounds …

I try that right now !

I wouldn’t advise doing this. I’ve seen icon data in the extended attributes of a file system object, for which you’d still need a declare to get at.

Apple provide a handful of public API to access the icon, which auto handles whatever format and location Apple use today to store the data. The thing about having all these functions, is when one gets broken in an OS update, you can fall back t’others in the time of need. Until they Apple deem that reading (and writing) custom icons is as dangerous as selling a car without a steering wheel or brake pedal :wink:

If your application is managing the icons, then sure, use whatever you feel is the best way. I thought you were trying to read icons that the user may have added.

Heck you can get something like PNGquant to compress the PNG even further. I see Xojo is now using this with Xojo 2021 Release 3.

OK for the warning. I already trashed my testing folder (and the associated AppleScripts used to rename etc. the test icon file). (1)

In fact, it is both. I explain: the user own (creates) the data inside the master folder. (s)he only have to add some more data (but I do not like that: the less work the user do, the better I feel).

Heck you can get something like PNGquant to compress the PNG even further. I see Xojo is now using this with Xojo 2021 Release 3.
Thank you for the information.

GIMP generate larger png files vs Preview (and Xojo prior 2021r3 ?).

In the mean time, I implemented the workaround and it works fine.

(1) Long time ago, and on Windows, I decoded the file Thumbs.db and extracted (for use) the jpg Thumbs files. Thus the idea to search if I can deal with the invisible Icon file.