20

I appreciate the "open" terminal command to launch OS X apps. When invoking the open command for any purpose, it is overwhelmingly likely that I will have at least one other command I would like to type into the terminal before tending to the application I have just summoned.

How do I keep focus on the terminal when using the open command?

3
  • Instead of piping through grep, have you just read the manage for open? Apr 29, 2015 at 3:41
  • 1
    In deed I missed the -g option when I read through it the first time. I only started grepping when I ran out of ideas. Thank you. Apr 29, 2015 at 3:49
  • I was looking for the opposite as the default behaviour seems to have changed in recent macOS versions and found out you have to uncheck Terminal → Secure Keyboard Entry to allow opened application to become frontmost. Dec 5, 2022 at 8:05

1 Answer 1

25

Use the -g flag.

From the man page:

-g Do not bring the application to the foreground.

Example: To open the folder at your current path, behind the current Terminal window:

open . -g

As a side note, it is often better to manually peruse the documentation for new commands, as the verbiage may be different from what you expect:

i.e. "Do not bring the application to the foreground." vs. "Maintain terminal window focus."

2
  • 1
    Thanks, I did give the man page a good read through, though apparently I fell short of a good perusal. I did try a few others other than 'focus', like 'background', but 'foreground' never occurred to me. Apr 29, 2015 at 3:51
  • No worries! It happens to the best of us! :)
    – ryebread
    Apr 29, 2015 at 4:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .