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 have an application that I want to launch via a shell script that does some setup and then launches the app itself with some specific options. Ideally, this script would be run whenever the application would normally be launched, i.e. when I click on it in the dock, double-click in the Applications folder, launch from QS, or even click on a file that opens in this app.

Right now I have an applescript wrapper "App" for my script, but the downside is that it appears as a separate app from the main app that sits in my dock, so I have to remember to not click on the main app's icon, but launch this alternate app instead.

So is this something that is possible to do? One idea I had is to rename the main executable in the app to something else, and then replace it with my script. Is that a reasonable thing to do, or is there a better solution?

For those who are curious, I am trying to set up Emacs.app to launch a daemon and then open using emacsclient. Basically, I want to have this script launch instead of emacs (and I'm going to modify the script to take file arguments and open them as well).

share|improve this question
    
I am confused by wgat you are doinf for Emacs - you can start Emacs.app using commdline arguments –  Mark May 31 '13 at 14:58
    
I want it so when I click on the Emacs app icon in my dock, it runs my script instead of the main Emacs executable. –  Ryan Thompson May 31 '13 at 15:18
    
Cool use case to learn about how to script things and tease apart what makes a clickable app versus a script. –  bmike May 31 '13 at 16:15

3 Answers 3

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

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

share|improve this answer
    
I can't comment on the main question or the reply you made with your final solution, but remember to mark it solved :) –  Jan Jun 1 '13 at 13:37

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.

share|improve this answer
    
I think I basically have everything solved except for one thing: when I "launch" the App by e.g. clicking on its Dock icon, I actually want it to execute my script instead. –  Ryan Thompson May 31 '13 at 17:44
    
You could use Platypus to make your script a clickable icon, copy the App's icon to your script and place your script in the dock, no? –  bmike May 31 '13 at 17:57
1  
Yes, I could, and in fact that is what I have now. But the app's windows would be grouped under its own icon, which would be separate from the script's icon. –  Ryan Thompson May 31 '13 at 18:08
    
Another way to approach it would be this: supposing I have my script packaged into an app using Platypus, is there any way to have my app "capture" the windows of the other app into its icon? –  Ryan Thompson May 31 '13 at 18:15
    
I don't see a way to sever the cocoa inheritance where one App controls it's windows - so you might be stuck with a helper app that does something before the main app executes or patching the main app to do what you desire in the first place. The third option is to have a second app that is intelligent enough to manipulate the first app to do what needs to be done as the main app runs and changes data/windows. That would be the most hard of all. –  bmike May 31 '13 at 18:20
up vote 1 down vote accepted

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!

share|improve this answer

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.