Run the script in ".app" (Application Bundle) as the main executable

I'm trying to use Mono to create a portable application that runs on Windows, Mac and Linux, but I want to have a standard DMG file that allows users to simply click and drag my application into the Applications folder on their mac. In the best answer to this post, I found that by creating an executable script file starting with #! in the MyAppName.app/Contents/MacOSX/ folder, it can run anything I liked.

How can I run a script?

I made an empty "Hello World" Cocoa App in Xcode and copied the .app file to the application directory and it worked fine. But when I replaced the executable in the MacOSX script folder, starting with #! he did not run the script.

I tried chmod 755 myscript , I tried to delete the old executable and rename my script as the old file name, but all that was done was to stop the application from starting. The script and file name permissions are correct.

So, I suggested that the scripts might not work, and XCoded is a command line utility, again, that just launches "Hello World!", But it still didn't start.

The “.app” extension is formally called an application package and they have pretty good documentation, but none of this tells me why my approach does not work.

Here is the .app package I'm working on. In the MasOSX directory you will find hello (Hello Word line command) and script (one line of script with #! As the first line) and XCodeTest (Hello World Cocoa application).

+4
source share
1 answer

Scripts on Unix

Well, firstly, the correct syntax for the first line of the script is

 #! <path-to-script-interpreter> [<optional-args>] 

for instance

 #! /usr/bin/perl -wT ... perl code here 

Using the open command

However, this will not help you, because the open command does not support shell scripts as launchers. You need to write C / Objective-C code and compile it into your own executable. Just using system() or execv() inside this tool won't work either, you need dlopen() Mono runtime.

Take a look at monodevelop / mainbuild / MacOSX / monostub.m for an example. This is what MonoDevelop uses to run the MonoMac application.

When you write a Cocoa application with Xcode, it compiles your application into its own code and places the resulting binary as a launch in the Contents/MacOS directory.

A simple solution

Why don't you just create a MonoMac app with MonoDevelop? This would automatically create the .app package for you - no need to mess with scripts or custom launchers.

+4
source

All Articles