0

I was writing a .sh script for opening a bunch of apps and i was looking for a way to force my apps to launch minimized.

The open command man page usage prompt, (displayed when you run open without args) says:

-j, --hide Launches the app hidden.

but some apps are still opening in the foreground (i.e. Chrome and Airmail).

I'm running El Capitain (10.11.6) and using zsh.

Do you know why those apps behave like that or if there's another way to accomplish this in bash?

Thanks.

3
  • What version of macOS are you using? -j is not listed in the man page in El Capitan, or Mavericks, for that matter.
    – tubedogg
    Commented Oct 13, 2016 at 19:30
  • i'm running El Capitain (10.11.6). I'm updating my question to add some more infos.
    – 6160
    Commented Oct 13, 2016 at 20:19
  • 1
    @le_vine This is because GoogleChrome uses different approach to display the app. Check the .app bundle and You'll see that it spawns the /Applications/Google\ Chrome.app/Contents/Versions/XX.X.XXXX.XX/Google\ Chrome\ Helper.app processes. When newer version of GoogleChrome is installed only the filder in Versions is changed. Commented Oct 17, 2016 at 13:33

1 Answer 1

3
+50

Google Chrome uses different mechanism to display the app, so the standard -j switch does not work as expected in this case. Main process spawns the Google Chrome Helper processes for every tab. If you check the .app bundle, you'll see it resides in /Applications/Google\ Chrome.app/Contents/Versions/XX.X.XXXX.XX/Google\ Chrome\ Helper.app. You can't launch it directly, because main app has to be running.

I couldn't find the other way around than just creating osascript like this:

open -j /Applications/Google\ Chrome.app && sleep 1 && osascript -e 'tell application "System Events" to set visible of application process "Google Chrome" to false'

However this will create 1 sec. delay in your script.

2
  • i'll try that right now! so basically this is what macOS do when i check the hide checkbox in the Login Items page inside user settings?
    – 6160
    Commented Oct 20, 2016 at 9:59
  • it works! for some apps (i.e. airmail) i have to set a bigger sleep time but it works fine! thanks
    – 6160
    Commented Oct 20, 2016 at 10:16

You must log in to answer this question.

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