Skip to content

Instantly share code, notes, and snippets.

@caldwell
Created February 25, 2013 00:44
Show Gist options
  • Save caldwell/5026535 to your computer and use it in GitHub Desktop.
Save caldwell/5026535 to your computer and use it in GitHub Desktop.
I put this little script my PATH so that I can call emacs from the command line and have it launch Emacs.app and not the built in emacs.
#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs "$@"
@caldwell
Copy link
Author

So you're saying that

cd ~/developer/project
emacs relative/path

tries to open ~/relative/path?

I just tried the same thing and it was working for me. I'm not sure what could causing that. Perhaps something in your .emacs file? Try with emacs -q and see if you get the same behavior.

@luisgerhorst
Copy link

I suggest using

#!/bin/sh
open -a Emacs "$@"

instead because it also works when Emacs is already open (the one above makes a second Emacs app show up in my Dock). It also seems to be better than

#!/bin/sh
which osascript > /dev/null 2>&1 && osascript -e 'tell application "Emacs" to activate'
emacsclient -c "$@"

or similar emacsclient stuff because it also works when Emacs is not running. The last one only opens Emacs but does not open the file when Emacs is not running.

@naxels
Copy link

naxels commented Jan 12, 2023

@caldwell , could you update the Tips And Tricks to also mention that the script should be executable chmod +x emacs
else it won't work.

For everyone else, I've gone a different route that mimics the way other apps create references in the path:

(make sure to use a user account that can become superuser/admin)

sudo ln -s /Applications/Emacs.app/Contents/MacOS/Emacs /usr/local/bin/emacs

This way you don't have to worry about cli args as the original executable will take care of it.

@caldwell
Copy link
Author

caldwell commented Feb 9, 2023

@naxels Yeah, that's probably much easier. I've changed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment