5

Sometimes when opening apps I get duplicate icons in the Dock for that app. This isn't really a problem, however I'm curious why macOS does this (I suppose this is more of a technical question).

This happens a lot especially with VS Code where I often launch the app with the code utility in the Terminal.

Why does macOS think these are different apps when they're the same binary?

Dock screenshot

  • 2
    Do you have the Show recent applications in Dock checkbox checked in System Preferences > Dock? – IconDaemon Feb 24 '21 at 00:19
  • I think this is dependent on the app and how it is started. If there are two seperate instances of the app, there will be 2 icons. – Gilby Feb 24 '21 at 02:08
  • @IconDaemon Yes but that only controls whether the 3 last recently used apps get shown in the small group second from the right. If I turn that off an open VS code then it'll open in a separate icon and not the one I have pinned. – Decade Moon Feb 24 '21 at 05:31
  • @IconDaemon And why would VS code appear in the recently used apps group when it is already pinned to the Dock? That shouldn't happen. – Decade Moon Feb 24 '21 at 05:35
  • OK. That doesn't explain it. Perhaps Gilby has a clue as to what is happening. – IconDaemon Feb 24 '21 at 12:09

3 Answers3

3

I don't have a specific answer as to what causes macOS to do this, however there is an issue on the VS Code GitHub repository which has lots of discussions about this (for VS Code app at least).

It seems to have something to do with launching an app directly (executing the binary inside XYZ.app/Contents/MacOS) instead of via Launch Services (the open command).

  • You have answered your own question - I like that!! Just to confirm, I can get extra instances (and extra icons) for Safari by saying open /Applications/Safari.app/Contents/MacOS/Safari in Terminal. But open /Applications/Safari.app just opens the existing Safari window. – Gilby Feb 25 '21 at 07:06
1

Passing the -n flag when using the open command opens multiple instances of an app. For example, running open -n -a Terminal several times will open multiple instances of the terminal app, as seen below

Terminals

twlscnds
  • 1,077
0

Just dropping in here the solution mentioned in the issue pointed by @Decade Moon for easy reference.

Apparently to avoid launching multiple VS Code instances you must use the Finder "open" interface instead of calling the VS code binary directly. This can be achieved by setting up an alias in your .zshrc or .bashrc like:

# Opening VS Code with Finder open so it is referenced as the same program in dock
alias code="open -b com.microsoft.VSCode"
JVGD
  • 101