0

I have at the core a very simple program. A shell script that can run on either mac or ubuntu. I have the requirement to distribute it on both platforms (in the mac case, must be a .app), however, I must build it exclusively on Ubuntu.

I was looking in to what is a mac '.app', and it seems like it's just a unique directory structure with executable, metadata, etc. For example, here are Apple's docs on the matter which explains it.

https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1

It seems like the metadata, etc. can all be put together, however in the Contents/MacOS folder, this is where the executable (the app's entrypoint) goes. This is the part I am confused on. For example, is there a way to make my shell script as an 'executable'? Or does this need to be a proper binary file (like you would get by compiling a C program?). If it is the latter, is there a way to do this on a Linux machine? (Noting that, this shell script, or C script I could make it in to, is so simple - essentially a single if/else statement which calls another utility.)

ffConundrums
  • 765
  • 9
  • 24

1 Answers1

1

You need to have two things:

  1. Put your executable into the Contents/MacOS directory, and make sure it is world-executable (just call chmod 755 on it). I think a shell script should work here, as long as it's got the correct "shebang" in front. For an actual binary, you'd need to find a way to compile a Mach-O binary on Linux.

  2. Next, you need to make an Info.plist file in the Contents directory. Just dig out any Apple plist file as a template, and put these keys in it:

    a. CFBundleExecutable—this should be the filename of your executable in Contents/MacOS

    b. CFBundleIdentifier—this should be a unique bundle ID for your application, in reverse-DNS notation, i.e. com.yourwebsitename.yourappname

If you have these components in your .app bundle, it should launch when you double-click on it.

Charles Srstka
  • 16,665
  • 3
  • 34
  • 60