When I start emacsclient from command line as below:

emacsclient -a '' -c "$@"

It always starts in the background (terminal window on top of emacsclient window), so I have to use mouse to click the window to switch to emacsclient.

It's really frustrating, can I get emacsclient to focus the frame that pops up when invoked from command line?

enter image description here

  • This is probably more a function of the window manager/desktop environment, than of emacs/emacsclient. In my case, the new frame pops up on top of the terminal window, e.g. (Gnome 3.20 on Fedora 24).
    – NickD
    Aug 7, 2017 at 21:52

3 Answers 3


You might be able to use the server-switch-hook and raise the frame. Something like:

(add-hook 'server-switch-hook #'raise-frame)

If that leaves you without focus on the new frame you might try something like this instead:

(add-hook 'server-switch-hook (lambda () (select-frame-set-input-focus (selected-frame))))

If you are looking to have a shell command to bring up an Emacs frame (without specifying one or more files to edit), you can also do this from the command line:

emacsclient -e "(raise-frame)"
  • It doesn't work. but it sounds like if add a filename at the command line, emacs will popup to foreground but without file to open, it will stay at background.
    – lucky1928
    Aug 8, 2017 at 19:43
  • If you don't need to pass file name arguments you can also call a function from the command line, e.g.: emacsclient -e '(raise-frame)'
    – glucas
    Aug 8, 2017 at 19:45
  • 1
    Your (select-frame-set-input-focus (selected-frame)) advice worked for me. May 25, 2018 at 16:23
  • 1
    I also couldn't get this to work using server-switch-hook, but it did work by adding the select-frame-set-input-focus... function to server-after-make-frame-hook. Not sure if there are any downsides to doing that instead...
    – apc
    Sep 2, 2022 at 21:21

This problem was also reported as an issue (see spacemacs issue #7078). The solution of using a wrapper script posted there worked for me. For completeness I will add the content of the script here:


if [[ "$#" -lt 1 ]] ; then
    emacsclient -c -e \
                "(select-frame-set-input-focus (selected-frame))" \
                "(delete-other-windows)" \
                "(spacemacs/home)" else
    emacsclient -c -e \
                "(select-frame-set-input-focus (selected-frame))" \
                "(delete-other-windows)" \
                "(find-file \"$1\")" fi

I do not have enough reputation points to comment here. But it would be great if information about where to place the server-switch-hook could be added to the answer by @glucas. In the end I did not get any of his solutions to work in a fully straightforward way...


I also encountered a similar issue. I need to use a timer to call select-frame-set-input-focus after a delay to ensure the newly created frame get focused:

(defun force-focus-selected-frame ()
    (run-at-time 0.1 nil
                 (lambda (frame) (select-frame-set-input-focus frame))
(add-hook 'server-after-make-frame-hook #'force-focus-selected-frame)

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.