How can I set up a shell script as a wrapper to the main executable of an app?

Solution 1:

Use /Applications/Emacs.app/Contents/MacOS/Emacs (or other executable in that directory).

Generally, application bundles are structured as above. Use Terminal to 'ls' your way to the file.

Solution 2:

I would start with a tool like Platypus to make your script have all the accoutrements of an App and test to see that things work as expected.

Automator also has a nice GUI for deciding how to handle arguments to a script - and we have several questions here that explore how to pass arguments into and out of an Automator action / applet.

Without more details on how your daemon is designed and how you launch it, I can only pick away at some of the elements to your solution, but since anyone can edit this answer to provide more details (or answer a stand-alone answer) - perhaps this can get the ball rolling to get you a solution.

Solution 3:

I was able to get what I wanted by going into the App folder Contents/MacOS and renaming the Emacs binary to Emacs.real. Then I put in my script and named it Emacs to replace the binary, and set it up to call Emacs.real after doing the necessary setup. Then launching the app launches my script.

Unfortunately, there are other issues with Emacs' daemon mode that prevent me from using it, but at least I solved this issue!