How can I stop a program, for instance Slack, which can have some significant loading time, stealing focus when it's finished loading?
If I start Slack, then switch focus during its loading time, the program steals focus when it's done loading. It drives me nuts.
Is there a way to prevent this behavior?
Best Answer
I found a couple options that should cover most applications. Either one of these could be used to create an Automator workflow to make running the script more convenient.
Option 1: Terminal command
The
open
command can be used to open an application using the-a
option. You can add the-g
option to open the application without bringing it to the foreground. This does not work for Slack or Google Chrome. I suspect it is because they are cross-platform applications that are built differently and aren't perfect macOS citizens. This solution is preferable if it works for the desired application.Option 2: AppleScript
You can use AppleScript to activate an application and hide it if it had not previously been running. The application will launch and still steal focus, but the script will delay a short time to ensure the application launches before trying to hide it. It's definitely not a perfect solution, but it works.
See this answer for several commands for opening new windows if that is desired.