If you launch emacs from the command line, here is a solution I've been using.
First, install emacs
and emacsclient
from homebrew cask.
Then, write a shell script:
#!/bin/sh
# "[E]emacs" prevents grep from finding grep process itself.
if ps -e | grep '[E]macs.app' > /dev/null; then
# Look for homebrew path: unnecessary if it's already in PATH.
if test -x /opt/homebrew/bin/brew; then
brewtopdir="/opt/homebrew"
elif test -x /usr/local/bin/brew; then
brewtopdir="/usr/local"
fi
$brewtopdir/bin/emacsclient -n "$@"
else
open -a "Emacs" --args --chdir "$PWD" "$@"
fi
# The --chdir argument is necessary if we want to pass relative paths to Emacs.
Let us call this script emacs
and place its path before the real emacs command. Then
$ emacs firstfile.txt # -> Launches the GUI emacs
$ emacs secondfile.txt # -> calls emacsclient
I wish I knew how to turn this shell script into a double-clickable "app" . . .
emacs
on the command line, or double-click on the Emacs icon in Finder, it happens. There is nothing wrong with opening two (or more copies), but keeping with how all other apps work on the Mac, opening one instance of apps is the norm.--with-ns
option, the same is true. [Building from source requires current versions ofautoconf
andautomake
and the command-line Developer utilities.]/usr/bin/emacs
, which has caused me problems in the past. And, I recently spent a bunch of time becauseetags
ships with OSX and is also outdated. I'm glad you found the issue. Please feel free to write up an answer with the solution, and rephrase anything in the question or title so that the question/answer is helpful to someone who Googles a similar problem and/or searches this forum directly. You will be able to accept your own answer in something like 24 or 36 or 48 hours.