Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm trying to shoe-horn a shell script into an application bundle so that the shell script will be run when I open the bundle, as opposed to the executable put in there.

Specifically, I'm trying to do some environment setup before running the binary, e.g. setting environment variables (I already tried just putting the environment variables into the Info.plist, which didn't work, presumably because MATLAB is stupid), and when I cd into the bundle and manually execute my script, (./StartMATLAB) it works; The program launches, and the environment variables are recognized.

When I double-click on the .app in Finder, or call open MATLAB_R2011b.app however, it fails. When calling open from the commandline, I get:

LSOpenURLsWithRole() failed with error -10810 for the file /Applications/MATLAB_R2011b.app

I've tried playing around with the Info.plist to no avail, but I'm not too familiar with how they are put together. Does anyone know why I cannot open this bundle?

Thanks!

EDIT: The Info.plist for the program I'm trying to edit seems to have a lot of java-related stuff. I've tried to remove it, but no luck so far. I'm thinking the problem may be with the .plist file, as it is expecting a java-based program as opposed to any other executable

share|improve this question
    
Does anyone else feel that this is a development question more suited to Stack Overflow? –  Jason Salaz Oct 8 '11 at 5:56
    
I wasn't sure, as it's not specifically programming, but it is very mac-related –  staticfloat Oct 8 '11 at 17:50
add comment

3 Answers 3

This won't work for a signed app, but here's how I was able to get this to work:

  1. Create a copy of the app you're trying to modify in case something goes wrong. (D in Finder) For my example here, I modified the non-app store version of VectorDesigner

  2. In Terminal, cd /Applications/VectorDesigner.app/Contents/MacOS

  3. mv VectorDesigner VectorDesigner\ copy (substitute the name of your app here

  4. pico VectorDesigner (or your editor of choice) and add the contents of your script.

    I used this script

     #!/bin/sh
     osascript -e "tell Application \"Finder\" to display alert \"Hello World\""
     /Applications/VectorDesigner.app/Contents/MacOS/VectorDesigner\ copy
    

    The important thing is for the last line to call the renamed executable.

  5. chmod a+x VectorDesigner

Now, when I double-click the VectorDesigner icon, I get the "Hello World" window, then it launches the original program.

share|improve this answer
    
This is exactly what I did for MATLAB above, however it silently fails when I double-click the icon, (Sometimes it has a MATLAB icon bouncing in the dock forever, but when I click on it it immediately disappears) and when I use open it fails with the error shown above. –  staticfloat Oct 7 '11 at 19:15
add comment

You probably need to change the file permissions, that seems to be the problem.

Open Terminal:

chmod +x /Applications/MATLAB_R2011b.app/Contents/MacOS/MATLAB_R2011b
share|improve this answer
    
My thought too, but setting execute permission was step 5 in another answer, and the OP reported he tried all those steps. –  Daniel Lawson Oct 8 '11 at 1:42
    
Yeap, I've already set it as executable. –  staticfloat Oct 8 '11 at 17:50
add comment

Instead of "shoe-horning" the script into the App bundle, what about doing it the other way around?

  1. Create a shell script that sets the environment as you want, and then launches the original App (with open for example). You said this works already.
  2. Embed the shell script in a new App bundle using Platypus.
  3. (optional) Embed the original App inside your new App bundle, and have your script launch it form there.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.