How to launch emacs GUI on OS X
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:
Create a directory under
/Users/Fred
, for instance,/Users/Fred/bin
where you store your own executable programs.Ensure that MacOS knows about your executable directory at login by editing the settings in ~/.MacOS/environment.plist .
Create a file called ~/bin/emacs . In it put the lines
#!/bin/sh exec /Applications/Emacs.app/Contents/MacOS/Emacs $*
Ensure that the file has execute permission:
chmod a+x ~/bin/emacs
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
The advantage of this approach over using
open
is that you can now use command lines likesudo 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 "$@" & }
Related videos on Youtube
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, 2022Comments
-
trentonknight about 1 year
Does anyone know any tricks for launching
emacs
with GUI on OS X with the standard commandemacs
?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 over 12 yearsHave you tried
open -a ProgramName --args program_arguments
or/Applications/ProgramName/Contents/MacOS/binary_name program_arguments
? -
trentonknight over 12 yearsYah, I tried that originally but I want the simplicity of launching it with just plain old, 'emacs.' Thanks anyway.
-
-
trentonknight over 12 yearsI 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 over 12 yearsI 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 over 12 yearsYup, put it in my bash_profile:
emacs='open -a /Applications/Emacs.app "$@"'
-
Dror almost 11 yearsDoes 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 over 8 yearsHow do I prevent this from launching a second instance of GUI Emacs if one is already open?