Custom Icon overlay on Folder Alias

Hello. I need a way in Mac OSX to put an image overlay and/or change programmatically an Alias FolderItem Icon with a custom one
Do It is possibile ?
Thanks you
C

https://forum.xojo.com/24894-custom-icon-overlay-on-folder-alias

Posted more times due to a server timeout

You’d have to inspect Apple’s documentation
I’m not aware of any way

In “Backup To Go” we have a function that allows people to design a custom disk icon for the backup disk and then we apply it to the disk.

The steps we used are as follows:

  1. Use NSImage to obtain the system disk icon or folder icon in your case, then draw this to a Xojo picture.
  2. Draw the other icons on top of the previous image.
  3. Convert back to a NSImage
  4. Use the NSWorkspace to set as a custom icon to the file.

We use our own Retina Kit functions for handling NSImages, but you can also use the MBS plugin or MacOSLib.

[quote=207438:@Carlo De Simone]Hello. I need a way in Mac OSX to put an image overlay and/or change programmatically an Alias FolderItem Icon with a custom one
[/quote]
Since Sam & I obviously read different things its not clear WHAT you want to customize
Are you wanting a custom icon for a file type ?
Or to customize how the OS presents aliases ?

The first is reasonably easy to do
The second i’m not sure it can be done at all

hmmm… I understood that the op wants to apply a custom icon to a specific Alias. I didn’t think at the time that the OP may want to customize all Aliases. If that’s the case, then I’m out of ideas (except for hacking the CoreTypes.bundle).

I forgot where I have it, but I have an AppleScript that allows me to change a file icon (it takes the image from the Clipboard). *

I also saw non Xojo code to do that (where ?).

So, I will say that it is perfectly possible to do. As usual, the difficulty comes when we want to implement the feature.

  • I wanted to add this feature to one REALbasic project until I realized that the application will be running on Windows XP (and it is stil running on a Windows XP machine)… :frowning: or ;-:slight_smile:

[quote=207493:@Emile Schwarz]I forgot where I have it, but I have an AppleScript that allows me to change a file icon (it takes the image from the Clipboard). *

I also saw non Xojo code to do that (where ?).

So, I will say that it is perfectly possible to do. As usual, the difficulty comes when we want to implement the feature.

  • I wanted to add this feature to one REALbasic project until I realized that the application will be running on Windows XP (and it is stil running on a Windows XP machine)… :frowning: or ;-:)[/quote]

Could you share the AppleScript ? TIA.

No apple script because are not accepted for the appstore. I don’t need to change all system aliases icons.
I need to change only certain aliases (specific folder icon) with a custom one, or add an image overlay over the already changed icon
@Sam talkead about MBS … wich class can do that ?
Thank you
C

You can use a shell and the commandline tool SetFileIcon
Example

You may want to double check exactly with the MBS documentation, but it would be the NSWorkspaceMBS and the function name is setIcon: forFile:

You’ll also need to use NSImageMBS instead of the Xojo picture object (or do your drawing with the Xojo picture and then convert it to a NSImageMBS).

I’m sure @Christian Schmitz can give you the exact code to use with his plugin.

I really forgot where I have it.

What I recall is… it worked fine when running on the Finder, but I had troubles making it works on Xojo (Real Studio / REALbasic) at the time and this is why I realized the final used does not need it because it runs Windows XP (in a discussion with involved party).

On the paper, it had to work, but I may have troubles implementing it using Xojo…

Did you try Axel’s suggestion ?

[quote=207742:@Emile Schwarz]I really forgot where I have it.

What I recall is… it worked fine when running on the Finder, but I had troubles making it works on Xojo (Real Studio / REALbasic) at the time and this is why I realized the final used does not need it because it runs Windows XP (in a discussion with involved party).

On the paper, it had to work, but I may have troubles implementing it using Xojo…

Did you try Axel’s suggestion ?[/quote]

Axels method requires to install development tools. That is impossible for a user product.

Im playing around folderitem, alias etc.
I have something like:
Dim f as FolderItem
f = SpecialFolder.Documents
for i as Integer = 1 to f.Count

  if f.Item(i).Directory and f.Item(i).Alias then
    
    myListbox.AddRow(array(f.Item(i).Name,"",""))
    myListbox.RowTag(myListbox.ListCount -1) = f.Item(i).ShellPath
    
  end if
next

The listbox is not populated. I’m sure I have many folder aliases in Documents, but f.Item(i).Alias is always false …
I’m on OSX Yosemite with Xojo2015r2.3, Is It a BUG ?
Does anyone has the same issue ?
Thanks,
C

Yes, I have (I Copy / Pasted your code in my main window and fire the current project.

I feel it have something related to the And (in the If block)…

Yes, that is it:

Replace and by Or and you will be done.

That said; the line below is really bad:

for i as Integer = 1 to f.Count

a. You instantiate (?) i at each loop run (f.Count times the small task),
b. f.Count is computed each time the software runs in the For … line !

But for testing, who cares ?

Sorry Emile, but yor answer don’t solve the isssue.
I have no listbox populated…
consider the if statement:
if f.Item(i).Alias then
add rows
end if
No aliases are found … continue to think there is bug…
Any idea ? Do Im wrong on something ?
Thanks
C

Unfortunately the advice was right here.

[code]Dim f as FolderItem
f = SpecialFolder.Documents
for i as Integer = 1 to f.Count

if f.Item(i).Directory Or f.Item(i).Alias then // Changed original And to Or

myListbox.AddRow(array(f.Item(i).Name,"","")) // Changed original myListbox to LB (name of my ListBox)
myListbox.RowTag(myListbox.ListCount -1) = f.Item(i).ShellPath // Changed original myListbox to LB (name of my ListBox)

end if
next[/code]

Why don’t you try to add all entries first ?
So you will be sure that the code works; then, add slowly a differentiation (if f.Directory Then myListbox.AddRow f.item(i).ShellPath, etc.)

For Alias, I suggest you read this.

Item resolve alias (OS X), what will happens if the alias cannot be resolved ?

Try TrueItem (instead of Item) to avoid alias resolution and watch what happens.

This have been read 362 times, so I assume there is no bug in f.Alias