How to launch emacs GUI on OS X

6,905

Solution 1

You could create an alias such as:
alias emacs = "open -a ProgramName"

Solution 2

If the following is within your realm of expertise it may be worth doing:

  1. Create a directory under /Users/Fred, for instance, /Users/Fred/bin where you store your own executable programs.

  2. Ensure that MacOS knows about your executable directory at login by editing the settings in ~/.MacOS/environment.plist .

  3. Create a file called ~/bin/emacs . In it put the lines

    #!/bin/sh
    exec /Applications/Emacs.app/Contents/MacOS/Emacs $* 
    
  4. Ensure that the file has execute permission: chmod a+x ~/bin/emacs

  5. Depending on your success with 2 (and whether or not you have logged out and in) you should be able to execute emacs with either just emacs or [worst case] with ~/bin/emacs

  6. The advantage of this approach over using open is that you can now use command lines like sudo emacs --user Fred /etc/something-owned-by-root. The --user Fred being useful if you have heavily customized emacs.

Solution 3

Are you using bash? With this bash function definition in your .bashrc (or whatever file you source your bash aliases from), 'emacs <stuff more stuff>' will do what you expect, including leaving your terminal back at the prompt immediately after launching emacs.

emacs() { /Applications/Emacs.app/Contents/MacOS/Emacs "$@" & }
Share:
6,905

Related videos on Youtube

trentonknight
Author by

trentonknight

I am Currently enlisted in the Coast Guard. However I aspires to someday be an all powerful programmer capable of create code so complex I cannot even figure it out!

Updated on September 18, 2022

Comments

  • trentonknight
    trentonknight about 1 year

    Does anyone know any tricks for launching emacs with GUI on OS X with the standard command emacs?

    I'm a ten year Linux user and thought I would buy a Mac for a while to stay diverse. I can open files via emacs now with open file.txt, but that wont allow me to use debugging mode.

    • HikeMike
      HikeMike over 12 years
      Have you tried open -a ProgramName --args program_arguments or /Applications/ProgramName/Contents/MacOS/binary_name program_arguments?
    • trentonknight
      trentonknight over 12 years
      Yah, I tried that originally but I want the simplicity of launching it with just plain old, 'emacs.' Thanks anyway.
  • trentonknight
    trentonknight over 12 years
    I tried it and its nice but its almost not emacs anymore itsso customized. It kinda takes all the fun of being miserable and manually adding all my el files. Also it rejected my .emacs file completely. I sure there is a work around but why bother when I want a purer version of emacs anyway. Thanks.
  • trentonknight
    trentonknight over 12 years
    I made a few changes but your answer was on point. This is what I have in my .bash_profile on Lion: alias emacs='open -a /Applications/Emacs.app "$@"'
  • trentonknight
    trentonknight over 12 years
    Yup, put it in my bash_profile: emacs='open -a /Applications/Emacs.app "$@"'
  • Dror
    Dror almost 11 years
    Does it make sense to add a test whether there's an emacs-server running (as per @DougHarris) and if so, then use it to visit the file. And otherwise, start a new session of emacs?
  • incandescentman
    incandescentman over 8 years
    How do I prevent this from launching a second instance of GUI Emacs if one is already open?