help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cannot start Emacs from Finder on macOS Ventura


From: Eric Swenson
Subject: Cannot start Emacs from Finder on macOS Ventura
Date: Mon, 9 Jan 2023 23:11:51 +0000

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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]