4

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).

5
  • I am confused by wgat you are doinf for Emacs - you can start Emacs.app using commdline arguments
    – mmmmmm
    Commented May 31, 2013 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. Commented May 31, 2013 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
    Commented May 31, 2013 at 16:15
  • This is exactly, what I am looking for. Might you poste your AppleScript here? I haven't worked with AppleScript before, so I am curious, how to do it.
    – Jan
    Commented Jan 21, 2022 at 8:25
  • 1
    @Jan I gave up on getting Emacs daemon to work properly on MacOS, and instead I wrote a package to simulate daemon mode without actually using daemon mode: github.com/DarwinAwardWinner/mac-pseudo-daemon Commented Jan 21, 2022 at 16:38

3 Answers 3

3

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.

1
  • I can't comment on the main question or the reply you made with your final solution, but remember to mark it solved :)
    – Jan
    Commented Jun 1, 2013 at 13:37
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.

5
  • 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. Commented May 31, 2013 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
    Commented May 31, 2013 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. Commented May 31, 2013 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? Commented May 31, 2013 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
    Commented May 31, 2013 at 18:20
1

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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .