I'm using iterm2 v3.0.2 with fishs hell and tmux in osx. When I'm opening file via emacsclient and closing buffer - I'm successfully returning to terminal, BUT iterm2 window has no focus, so I have to click on window to gain it. I tested behaviour inside tmux session and outside - the same behaviour.

My command to run emacsclient:

emacsclient -c -a \"\" $argv
  • That sounds more like a problem with your window manager than with Emacs. Maybe you could try a different one?
    – phils
    Apr 15, 2017 at 21:28

2 Answers 2


Maybe you can try to switch to your terminal app explicitly when C-x # (server-edit, the command to tell emacsclient that you finish editing):

(add-hook 'server-done-hook
          (defun open-terminal ()
            (shell-command "open -a Terminal")))

You also need to replace Terminal with iTerm since you are using iTerm2, not the built-in Terminal. I don't have iTerm2 installed on my Mac, so I can't try it myself.

  • nope, didn't helped(
    – sandric
    Jun 18, 2016 at 17:29

I had the same problem, and managed to get it working by adding

(defun switch-back-focus ()
  (shell-command "open -a iTerm"))

(add-hook 'server-done-hook 'switch-back-focus)

to my init.el file.

This does come with a couple of caveats - it will bring any Emacs frames to the front before it move back to iTerm2.

Thanks to @xuchunyang!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.