1

I've followed the advice laid out in How to launch GUI Emacs from command line in OSX? and on the Emacs for mac osx how-to page to setup my GUI emacs so that it grabs focus on startup.

When I run an emacs standalone session, emacs GUI properly grabs focus and focus is returned to my terminal upon killing my emacs frame.

However, killing my emacsclient frame (aliased to this script) with C-x C-c does not return focus to the terminal.

Is there a good way to do this?

update M-x kill-emacs does return focus to terminal. So the issue is killing that emacsclient frame specifically.

  • You may need an applescript to achieve your goal. – lawlist Nov 26 '17 at 17:26
  • My special issue is similar. I have configured my git to use external editor for commit message. After I have closed the editor the terminal (iTerm) is getting back the focus. – takacsot Jun 06 '18 at 09:52

1 Answers1

1

I solved this problem by running an Applescript to 1) note the current application, 2) launch Emacs and wait, and 3) return focus to the then-current application. It looks like:

tell application "System Events"
    set frontApp to (path to frontmost application as Unicode text)
end tell

do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c"

activate application frontApp
Handyman5
  • 131
  • 3
  • In the intervening year, somebody implemented [mac-pseudo-daemon](https://melpa.org/#/mac-pseudo-daemon) which uses emacs hooks to call Applescript to hide the emacs window when a graphical frame is closed. Much easier! – Handyman5 Jan 01 '20 at 00:28