Recent

Author Topic: [RESOLVED] Minimum files to distribute and how to set application icon  (Read 12399 times)

pasquale

  • Full Member
  • ***
  • Posts: 183
    • Esposito Software
Hello, everybody.

After many years, I made up my mind to buy a Mac and now I am trying to understand how to develop applications with Lazarus for that operating system.

I have a couple of questions I would like to ask you.

When I compile an application with Lazarus I get a compiled file called, for example, Project1, which is accompanied by another file of the same name (so, it looks like the file extensions are not shown in Lazarus).

I have noticed that if I want to make my app work in another folder, I have to move both Project1 files there otherwise the app will not start.

Now my questions are:

(1) Is it the right procedure to follow if you want to deliver your application to a user who does not have Lazarus installed on his or her Mac? Of course, by "right procedure" I mean providing a folder containing the two above mentioned files.

(2) Is it possible to change the icon of your application so that the user will not see the default app icon provided by Mac? Needless to say, I have loaded an icon in the Project options but it looks like it was useless.

Thank you in advance for your help.
« Last Edit: March 19, 2012, 06:45:47 pm by pasquale »
I'm beginning to love the Mac and hate Apple's money-hungry policy.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8273
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Minimum files to distribute and application icon
« Reply #1 on: March 18, 2012, 01:46:23 pm »
Use this for Mac (it's a simple checkbox in project options).

pasquale

  • Full Member
  • ***
  • Posts: 183
    • Esposito Software
Re: Minimum files to distribute and application icon
« Reply #2 on: March 18, 2012, 03:18:15 pm »
Thanks.

About creating a setup package for your Mac applications, I have read that Apple provides Package Maker for free, which comes highly recommended.

Suppose I don't want to create a setup package but just give the final user the minimum number of files necessary to run my program. Is it possible to replace the default application icon with a customized one?
I'm beginning to love the Mac and hate Apple's money-hungry policy.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1138
    • formatio reticularis
Re: Minimum files to distribute and application icon
« Reply #3 on: March 18, 2012, 07:55:49 pm »
Is it possible to replace the default application icon with a customized one?

Yes, put a icns file into the folder Contents/Reources/ within your application bundle and set the value of the key "icon file" to the name of your icns file within your info.plist file in Contents/, either with the Property List Editor or manually with

<key>CFBundleIconFile</key>
<string>example.icns</string>


Apart from using the excellent shell script described in the wiki page cited by Leledumbo you may also manually copy the executable to the folder Contents/MacOS/ within your bundle, thus replacing the alias that was there. However, if you make frequent builds, the shell script may save time and efforts.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

pasquale

  • Full Member
  • ***
  • Posts: 183
    • Esposito Software
Re: Minimum files to distribute and application icon
« Reply #4 on: March 18, 2012, 08:10:51 pm »
Thanks, jwdietrich.

I have just realized that Lazarus creates a bundle automatically when you run and compile your application, so the default icon I saw was actually a folder containing the structure of a typical application for Mac (I thought it was a single file).

If I understand correctly, Lazarus does not export the icon that you load to the project options to the Contents/Reources/ folder of the bundle and, consequently, you have to do it manually. I'll give it a try.

I still don't understand why I get a second file together with my bundle. I'm referring to the file named as the project that is not within the bundle but out of it. Shouldn't a bundle be self-sufficient?

Thanks again for your help.
I'm beginning to love the Mac and hate Apple's money-hungry policy.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1138
    • formatio reticularis
Re: Minimum files to distribute and application icon
« Reply #5 on: March 18, 2012, 08:28:25 pm »
If I understand correctly, Lazarus does not export the icon that you load to the project options to the Contents/Reources/ folder of the bundle and, consequently, you have to do it manually. I'll give it a try.

You might submit a bug report about this unexpected behaviour that has annoyed me and certainly many others, too.

I still don't understand why I get a second file together with my bundle. I'm referring to the file named as the project that is not within the bundle but out of it. Shouldn't a bundle be self-sufficient?

Yes, but Lazarus developers say that providing the binary outside the bundle facilitates debugging.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: Minimum files to distribute and application icon
« Reply #6 on: March 18, 2012, 08:28:39 pm »
Thanks, jwdietrich.

I still don't understand why I get a second file together with my bundle. I'm referring to the file named as the project that is not within the bundle but out of it. Shouldn't a bundle be self-sufficient?


Yes, an app bundle should be self-sufficient as much as possible. That's kind of the whole point - see how Xcode itself is now a self-sufficient app bundle. Why Lazarus creates the executable outside the bundle and then symlinks to it from within the bundle is one those great unsolved mysteries of Lazarus.

I see that someone adapted my script for creating an app bundle and posted it to the wiki. It appears to provide an option for copying the executable into the app bundle.

Usually there are a number of things that you will want to do to make your Laz app more like a normal OS X app. See notes here:

http://web.me.com/macpgmr/ObjP/MacXPlatform_Part8.html

Also, if you don't need cross-platform, you could just do your app with Xcode and Cocoa (32- or 64-bit), as described here:

http://web.me.com/macpgmr/ObjP/Xcode4/

Thanks.

-Phil

pasquale

  • Full Member
  • ***
  • Posts: 183
    • Esposito Software
Re: Minimum files to distribute and application icon
« Reply #7 on: March 18, 2012, 09:46:54 pm »
I modified the info.plist file following the directions above and now I get an error message when I move the bundle to another folder -- together with the accompanying binary file -- and try to launch it, nor can I see the icns file I put in the resources.

About the binary file, it would be very interesting to know how to move it within the bundle.
I'm beginning to love the Mac and hate Apple's money-hungry policy.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1138
    • formatio reticularis
Re: Minimum files to distribute and application icon
« Reply #8 on: March 18, 2012, 09:54:38 pm »
This surprises me. I have used this trick multiple times in several of my projects without any problem.

Can you tell us more about the error message?

Do you have administrator privileges?
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

pasquale

  • Full Member
  • ***
  • Posts: 183
    • Esposito Software
Re: Minimum files to distribute and application icon
« Reply #9 on: March 18, 2012, 10:20:38 pm »
Hold on! I tried again and this time it worked!

To make the icon appear, I had to move my bundle with its binary file to another folder and then drag them back to their original position.

To make things perfect, now I should learn how to move the accompanying binary file into the bundle. I think it would be more professional to be able to deploy all the application in a single bundle.

Phil, when you said "It appears to provide an option for copying the executable into the app bundle", did you mean that somebody managed to embed the binary file in the bundle?

Thanks.

I'm beginning to love the Mac and hate Apple's money-hungry policy.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1138
    • formatio reticularis
Re: Minimum files to distribute and application icon
« Reply #10 on: March 18, 2012, 10:25:19 pm »
To make the icon appear, I had to move my bundle with its binary file to another folder and then drag them back to their original position.

Sorry, I forgot to mention this. It forces the finder to flush the cashes and redraw the icon.

To make things perfect, now I should learn how to move the accompanying binary file into the bundle. I think it would be more professional to be able to deploy all the application in a single bundle.

This can be done by hand as mentioned above or with the script.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

pasquale

  • Full Member
  • ***
  • Posts: 183
    • Esposito Software
Re: Minimum files to distribute and application icon
« Reply #11 on: March 18, 2012, 10:35:33 pm »
Quote
This can be done by hand as mentioned above or with the script.

Sorry, I'm probably missing something. I can't find where you explained how to hide the binary file within the bundle. Could you please tell me again?

Thanks a lot for your precious help.
I'm beginning to love the Mac and hate Apple's money-hungry policy.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1138
    • formatio reticularis
Re: Minimum files to distribute and application icon
« Reply #12 on: March 18, 2012, 10:38:18 pm »
Hide the binary file?
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

pasquale

  • Full Member
  • ***
  • Posts: 183
    • Esposito Software
Re: Minimum files to distribute and application icon
« Reply #13 on: March 18, 2012, 10:49:18 pm »
I'm afraid I could not explain what my problem was, so I'll try again.

When Lazarus compiles an application it produces a bundle, which looks like a single file, and then it also generates an external file of the same name as the bundle. (That's what I believed you meant by "binary file")

The presence of that second file is, in my opinion, quite disturbing as it would be much nicer to distribute a unique bundle to the final user. After all, in the OS X Application folder I have seen no bundles accompanied by external files.

For this reason, I was wondering whether it was possible to "hide" that external file by placing it within the bundle so that it would not be visible to the final user.

Was there a misunderstanding?
I'm beginning to love the Mac and hate Apple's money-hungry policy.

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: Minimum files to distribute and application icon
« Reply #14 on: March 18, 2012, 10:52:58 pm »

For this reason, I was wondering whether it was possible to "hide" that external file by placing it within the bundle so that it would not be visible to the final user.


This should work:

rm "yourapp.app/contents/macos/yourapp"
cp -p yourapp "yourapp.app/contents/macos"

Thanks.

-Phil

 

TinyPortal © 2005-2018