Lazarus

Programming => General => Topic started by: madref on August 09, 2019, 05:03:56 pm

Title: Changing the icon of a file
Post by: madref on August 09, 2019, 05:03:56 pm
On a Mac you can change the icon of a file when you show the 'Files Info' and drag-and-drop a icon-file(.icns) or a png-file over it.
Is this also possible to do this programmable?
Title: Re: Changing the icon of a file
Post by: trev on August 10, 2019, 01:23:16 am
Sure you can. You just need to replace the .icns file which can be found in the App bundle (Contents/Resources/???.icns).
Title: Re: Changing the icon of a file
Post by: jamie on August 10, 2019, 02:32:37 am
I guess it's nice to have resource files separated in a bundle, makes it simple to customize things, also makes it easy to get hacked and have undesirable end trails from the those that are not so savvy with code.

 Write protecting your folders won't save you at all points.
Title: Re: Changing the icon of a file
Post by: trev on August 10, 2019, 02:36:25 am
I'm not sure this can be done under the upcoming Catalina where apps require signing and notarization. I suspect that changing the .icns file might invalidate the stapled notarization.
Title: Re: Changing the icon of a file
Post by: madref on August 10, 2019, 02:40:23 am
Sure you can. You just need to replace the .icns file which can be found in the App bundle (Contents/Resources/???.icns).
Yes that is for an app. But how about a single file like a database-file
Title: Re: Changing the icon of a file
Post by: madref on August 11, 2019, 02:02:52 pm
I also found this:
https://stackoverflow.com/questions/38486934/how-to-programmatically-set-the-file-icon-on-os-x
But that is acacadabra for me
Title: Re: Changing the icon of a file
Post by: madref on August 13, 2019, 09:57:25 am
Can anyone help me?
Title: Re: Changing the icon of a file
Post by: trev on August 13, 2019, 11:16:48 am
Exercising my Google-Fu, I came up with https://developer.apple.com/documentation/coreservices/launch_services

Quote
macOS Launch Services is an API that enables a running application to open other applications or their document files in a way similar to the Finder or the Dock. Using Launch Services, an application can perform such tasks as:

    * Open (launch or activate) another application
    * Open a document or a URL (uniform resource locator) in another application
    * Identify the preferred application for opening a given document or URL
    * Register information about the kinds of document files and URLs an application is capable of opening
    * Obtain appropriate information for displaying a file or URL on the screen, such as its icon, display name, and kind string
    * Maintain and update the contents of the Recent Items menu

Icons for file types are therefore handled by Launch Services and the icon for a file is provided by the application handling opening a file by default.

The way an application provides its metadata to the system is through the use of a special file called an information property list file, or Info.plist.

So, you need to add your file type definition to the plist file of the application that will open it by default.

That should get you going without any abracadabra ;-)
TinyPortal © 2005-2018