Recent

Author Topic: Changing the icon of a file  (Read 1466 times)

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Changing the icon of a file
« 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?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Changing the icon of a file
« Reply #1 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).

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Changing the icon of a file
« Reply #2 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.
The only true wisdom is knowing you know nothing

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Changing the icon of a file
« Reply #3 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.

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Changing the icon of a file
« Reply #4 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
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Changing the icon of a file
« Reply #5 on: August 11, 2019, 02:02:52 pm »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Changing the icon of a file
« Reply #6 on: August 13, 2019, 09:57:25 am »
Can anyone help me?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Changing the icon of a file
« Reply #7 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