Recent

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

madref

  • Hero Member
  • *****
  • Posts: 690
  • ..... A day not Laughed is a day not Lived !!
    • 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 2.0.2 / FPC 3.0.4
Lazarus Trunc / FPC 3.0.4
Mac OS X Mojave

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 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).
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

jamie

  • Hero Member
  • *****
  • Posts: 2068
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.
Number 1 at blue screen app creations!

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 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.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

madref

  • Hero Member
  • *****
  • Posts: 690
  • ..... A day not Laughed is a day not Lived !!
    • 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 2.0.2 / FPC 3.0.4
Lazarus Trunc / FPC 3.0.4
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 690
  • ..... A day not Laughed is a day not Lived !!
    • 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 2.0.2 / FPC 3.0.4
Lazarus Trunc / FPC 3.0.4
Mac OS X Mojave

madref

  • Hero Member
  • *****
  • Posts: 690
  • ..... A day not Laughed is a day not Lived !!
    • 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 2.0.2 / FPC 3.0.4
Lazarus Trunc / FPC 3.0.4
Mac OS X Mojave

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 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 ;-)
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)