unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Cannot start Emacs from Finder on macOS Ventura
@ 2023-01-09 23:11 Eric Swenson
  2023-01-10  1:23 ` Emacs for early Macs? (was: Re: Cannot start Emacs from Finder on macOS Ventura) [screenshot] Emanuel Berg
  2023-01-11  1:04 ` Cannot start Emacs from Finder on macOS Ventura Eric Swenson
  0 siblings, 2 replies; 15+ messages in thread
From: Eric Swenson @ 2023-01-09 23:11 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org; +Cc: Eric Swenson

I recently decided to update my Homebrew-installed emacs, and because only version 28.2 was available, I decided to try the emacs-nightly HomeBrew cask.  Installation went find, and I’m able to invoke the GUI emacs by simply executing “emacs” in a zsh shell.  When I do, it comes up in the dock, and I can set the “Keep in dock” menu item from the dock icon’s Options context menu.  If I exit emacs, however, I’m unable to launch it via the dock, nor by clicking on /Applications/Emacs.app in Finder.  The only way I appear to be able to start it is via the command line.

It turns out that “emacs” is an alias:

➜  ~ which emacs
emacs: aliased to /Users/eswenson/.oh-my-zsh/plugins/emacs/emacsclient.sh --no-wait

This script looks like this:

#!/bin/sh

emacsfun() {
  local cmd frames

  # Build the Emacs Lisp command to check for suitable frames
  # See https://www.gnu.org/software/emacs/manual/html_node/elisp/Frames.html#index-framep
  case "$*" in
  *-t*|*--tty*|*-nw*) cmd="(memq 't (mapcar 'framep (frame-list)))" ;; # if != nil, there are tty frames
  *) cmd="(delete 't (mapcar 'framep (frame-list)))" ;; # if != nil, there are graphical terminals (x, w32, ns)
  esac

  # Check if there are suitable frames
  frames="$(emacsclient -a '' -n -e "$cmd" 2>/dev/null)"

  # Only create another X frame if there isn't one present
  if [ -z "$frames" -o "$frames" = nil ]; then
    emacsclient --alternate-editor "" --create-frame "$@"
    return $?
  fi

  emacsclient --alternate-editor "" "$@"
}

# Adapted from https://github.com/davidshepherd7/emacs-read-stdin/blob/master/emacs-read-stdin.sh
# If the second argument is - then write stdin to a tempfile and open the
# tempfile. (first argument will be `--no-wait` passed in by the plugin.zsh)
if [ $# -ge 2 -a "$2" = "-" ]; then
  # Create a tempfile to hold stdin
  tempfile="$(mktemp --tmpdir emacs-stdin-$USERNAME.XXXXXXX 2>/dev/null \
    || mktemp -t emacs-stdin-$USERNAME)" # support BSD mktemp
  # Redirect stdin to the tempfile
  cat - > "$tempfile"
  # Reset $2 to the tempfile so that "$@" works as expected
  set -- "$1" "$tempfile" "${@:3}"
fi

emacsfun "$@"

So “emacsclient –create-frame” is able to start emacs.

And emacsclient is:

➜  ~ which emacsclient
/usr/local/bin/emacsclient
➜  ~ ls -l /usr/local/bin/emacsclient
lrwxr-xr-x  1 eswenson  admin  54 Jan  9 14:50 /usr/local/bin/emacsclient@ -> /Applications/Emacs.app/Contents/MacOS/bin/emacsclient

So why is it that neither clicking on /Application/Emacs.app in Finder, or using Spotlight, or clicking on the dock icon for Emacs will bring up Emacs?

I’m running macOS Ventura.  I’m using an emacs-nightly Homebrew from this date/time: 2023-01-06_00-09-32.

-- Eric (KC6EJS)



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-01-16  0:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-09 23:11 Cannot start Emacs from Finder on macOS Ventura Eric Swenson
2023-01-10  1:23 ` Emacs for early Macs? (was: Re: Cannot start Emacs from Finder on macOS Ventura) [screenshot] Emanuel Berg
2023-01-10  2:11   ` Eric Swenson
2023-01-10  3:59     ` Emanuel Berg
2023-01-10  5:12   ` Emacs for early Macs? Po Lu
2023-01-10  5:43     ` Emanuel Berg
2023-01-10 10:33   ` Emacs for early Macs? (was: Re: Cannot start Emacs from Finder on macOS Ventura) [screenshot] Jean Louis
2023-01-10 21:57     ` Emanuel Berg
2023-01-11  1:04 ` Cannot start Emacs from Finder on macOS Ventura Eric Swenson
2023-01-11  3:03   ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-01-16  0:00     ` Eric Swenson
2023-01-11  6:25   ` Daniel Fleischer
2023-01-11  6:44     ` John Covici
2023-01-15 22:54       ` Eric Swenson
2023-01-15 23:55     ` Eric Swenson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).