Monday, April 25, 2011

Running a script when a Mac package is executed

I have a Mac OS X application in the standard .app format and was wondering what is the easiest way to have a small script execute before the main program does. Is that possible?


I only want to run the script once, so if I can set a flag or something after it runs that would be great!

Second Edit:

I do not have the XCode project so I cannot recompile anything, which is why I'm looking for another method.

From stackoverflow
  • Two possibilities:

    • If you have access to the Xcode project, you can put your script in the resources of your app, get its pathname with:

      [[NSBundle mainBundle] pathForResource:@"preamble" ofType:@"sh"]

      and invoque it with a simple system() call at the beginning of your main() function.

    • If you don't have access to the Xcode project, I am not certain whether it is possible. I would try something like substituting actual executable with your script and add a way to call the executable at the end of the script with an exec command.

  • What do you want the script to do? Is it not possible to launch it from within your application?

  • If the app is relatively simple, you could just repackage it in another bundle. You could write a short program to run the script and then launch their executable, which you'd want to include in your bundle as a resource.

    Of course, you'd also need to copy over all the original resources from the application.

    Might I ask which program you are trying to run in this way?

    Abdullah Jibaly : It's an Adobe AIR application, so I'm trying to install Adobe AIR if it hasn't been installed already. It's not a standard app (some files have been modified to support hardware integration) so I cannot use the standard AIR distribution mechanism.


Post a Comment