In case it's relevant, I'm on a Mac, running OSX 10.12 and Carbon Emacs 24.3.1.

If I open a file using /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n filepath the Emacs window comes to the top and gets focus unless opening the file triggers a minibuffer prompt (such as Symbolic link to Hg-controlled source file; follow link? (yes or no).

Is there a way to configure Emacs to grab focus and raise its window in these cases as well?

1 Answer 1


Assuming that are you using the GUI frame, basically you just need pass -e '(x-focus-frame nil)' as argument of emacsclient.

In that case: emacsclient -n -e '(x-focus-frame nil)' filepath

EDIT by OP: (You may need to use: emacsclient -n -e "(progn (x-focus-frame nil) (find-file \"filepath\"))" —— See documentation for emacsclient's -e parameter.)

I wrote a similar script to accomplish that here and another stuff for personal reasons. Mainly to avoid pain about opening multiple frames running on daemon mode like:

  • handling daemon crashing (and restarting for my init system [OpenRC])
  • be sure that when a frame exists, opening the file on it instead creating a new one
  • if a current frame was used, ensure that raises that frame and focus it.

The script is in some way portable and you can try to use it in the last case.

  • This got me there with a couple of changes: (raise-frame) did not work, but (x-focus-frame nil) did; and (empirically and from emacsclient --help) I can't use plain filepath to open a file if I also use -e. What worked for me: emacsclient -n -e "(progn (x-focus-frame nil) (find-file \"$1\"))" Commented Nov 3, 2017 at 14:36
  • Probably is different because you are running on Mac Os X? Works fine for me (raise-frame), I'm editing the answer. Commented Nov 3, 2017 at 21:21
  • About the filepath stuff, try executing in the way that I edited the answer, works fine here: keep the filepath on the last argument. Commented Nov 3, 2017 at 21:32
  • 1
    Wr.t. raise-frame -vs- focus-frame: they're both needed in general (the effect of either of them is dependent on the window system/manager in use).
    – Stefan
    Commented Nov 8, 2017 at 18:13

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.