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. – Diego Barros Nov 29 '17 at 05:03--with-ns
option, the same is true. [Building from source requires current versions ofautoconf
andautomake
and the command-line Developer utilities.] – lawlist Nov 29 '17 at 05:16/usr/bin/open Emacs
-- it must somehow seem different than when you double-click the app icon. So I changed the shortcut to run/usr/bin/open /Applications/Emacs.app
and the problem no longer happens. Thank you. – Diego Barros Nov 29 '17 at 05:45/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. – lawlist Nov 29 '17 at 06:16