Open app in a different desktop

I am trying to open an application on a different desktop on my MacBook (macOS Sierra Version 10.12.5).

In the screenshot, I assigned Chrome to a different space (Desktop 1). I go to Desktop 2 and when I click on the Chrome icon, I am automatically switched to Desktop 1. How could I stay on Desktop 2?

Chrome is assigned to Desktop 1

EDIT

Maybe the logs are helpful. Which process does trigger the desktop switch? Console - All Messages


Solution 1:

From comments - as this appears to work for the OP, though I couldn't get it to work myself, on El Capitan.

From Keep applications from stealing focus when opening in OS X - by Topher Kessler [so at least it has a good pedigree, but it's from 2011]

To have a program always open in the background, you will need to edit a property list in the program package and add a couple of lines to the file. To do this, follow these instructions:

  1. Locate the application package file for the program in question.

  2. Right-click and choose "Show Package Contents."

  3. Navigate to the "Contents" directory within the application and open the "Info.plist" file in a text editor.

  4. Add the following lines to the file (the easiest location is to place them immediately after the <dict> tag, before the first <key> tag at the top of the document):

    <key>LSBackgroundOnly</key>
    <string>True</string>
    
  5. Save and close the file, and close the application package windows

After doing this, the program should now launch behind others at all times, and then only be brought to the front if you click a window for the program. As a word of warning, editing the contents of applications will break their code signature, which is required for some applications to automatically work with system services like the application firewall. Without an intact code signature, the system may always ask for you to allow applications through the firewall when they are launched, which may be a bit of an inconvenience. Additionally, this may not work for all applications, but it not then you can easily remove the added lines to restore full functionality to the program.

The second option for affecting a launching program is to develop a script that will launch it in the background. The basics for this script are to use the "open" terminal command, with the "-g" flag in the following manner (using iCal as an example):

open -g /Applications/iCal.app

As an alternative to providing the full path name to the application, you can use the "-a" flag as well and then only supply the application name, such as the following:

open -ga iCal

With these commands, you can set up a launcher for your programs either using AppleScript or Automator, where the script runs this command as a shell script to target the application of choice. For example, to create a script that will always launch iCal in the background, open Automator and create a new application workflow. Then add the "run shell script" action to the workflow and paste one of the above commands into the action's script field. Then save the workflow and when you run it, iCal should open behind your current application.

One caveat appears to be that the application can not be closed properly, i.e. its process is still present after closing it.

Solution 2:

I have tried that in Yosemite but not in Sierra, but you could try to disable the desktop autoswitching.

Open terminal and enter:

defaults write com.apple.dock workspaces-auto-swoosh -bool NO

the restart the dock with

killall Dock

To revert to the default setting type

defaults write com.apple.dock workspaces-auto-swoosh -bool YES
killall Dock

Solution 3:

I get the performance you want by using the 'none' option when assigning an app to a desktop. But if the app is open on another desktop, you will be taken to that desktop if you try to open another instance of the app. I do not know a work around for this. Just be sure to not open app in a desktop other than the one you want. If there is a work around for this maybe another responder will know.