Lazarus
Programming => General => Topic started 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?
-
Sure you can. You just need to replace the .icns file which can be found in the App bundle (Contents/Resources/???.icns).
-
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.
-
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.
-
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
-
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
-
Can anyone help me?
-
Exercising my Google-Fu, I came up with https://developer.apple.com/documentation/coreservices/launch_services
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 ;-)