vscode: macOS Mojave: code command line generate duplicate "recently opened" icons in dock

Issue Type: Bug

$ code 
$ code
$ code

VS Code version: Code 1.28.0 (431ef9da3cf88a7e164f9d33bf62695e07c6c2a9, 2018-10-04T16:40:40.180Z) OS version: Darwin x64 18.0.0 (10.14)

screen shot 2018-10-11 at 10 13 51

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 105
  • Comments: 85 (33 by maintainers)

Commits related to this issue

Most upvoted comments

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

According to #62536, a temporary solution is this (for quick reference):

Ah, MacOS Mojave has started adding “Recent Applications” to the dock. Here’s an article that shows how you can turn off that

Looked into this a bit deeper. Calling the executable of any application from the terminal while that application is already running will result in the observed behavior, even for stock macOS apps. The solution would seem to be to rewrite code.sh so that it opens VSCode without calling the application executable or hope it gets patched in a future macOS version.

The former should be possible as Sublime Text’s similar subl command does not exhibit the behavior.

Yes, I can confirm that this is fixed in macOS Big Sur.

This issue is about seeing multiple Code icons in the recent portion of the dock:

image

Only reproduces when you enable this setting:

image

@bpasero I’m pretty sure that’s just an optical illusion. Change your background to a non-gradient and try it again

@bpasero I have tried on 10.14.1, it still reproduces

Below script save as code command, work fine for me

#!/usr/bin/env bash

open -b com.microsoft.VSCode "$@"

This issue is still reproducible on mac Os Big Sur Version 11.2.3

Screenshot 2021-03-22 at 15 06 12

I can confirm the problem with a fresh install of Mojave 10.14.3. This only happens when starting code from terminal and it’s already running, and if that option is activated in the Dock preferences (if it’s not, macOS does not add recent apps at the right of the dock so it’s not a problem of course):

image

One other thing to test out, does running code --list-extensions also trigger the issue?

code --list-extensions does not trigger this issue. open -b com.microsoft.VSCode does not trigger this issue. /usr/local/bin/code does trigger this issue.

@MikeMcQuaid’s workaround works for me:

alias code='open -b com.microsoft.VSCode "$@"'

Yes, I can confirm that this is fixed in macOS Big Sur.

This issue still exists: 截屏2020-11-23 下午7 38 57

mac mojava 1.14.5 Same problem here. 스크린샷 2019-07-31 오전 11 13 24

Having those multiple VS Code icons showing up in recents is helpful and we can easily switch between different opened workspaces.

It does not show the name of the workspace in the title or the active opened file, that way at-least we can distinguish between different VS Code instances.

Screenshot 2019-12-28 at 12 55 11 PM

Can confirm adding alias code='open -b com.microsoft.VSCode "$@"' in .bashrc and reload terminal will work on Big Sur. Code . will no longer brings up multiple icon Not sure about Mojave

Thank you!

And for zsh, alias code='open -b com.microsoft.VSCode "$@"' do not work, while alias code='open -b com.microsoft.VSCode' worked for me.

Can confirm adding alias code='open -b com.microsoft.VSCode "$@"' in .bashrc and reload terminal will work on Big Sur. Code . will no longer brings up multiple icon Not sure about Mojave

aha, I see - this problem occurs only if VS Code is launched from the command line.

Has anyone found any updated answers to this problem?

I did a slightly modified version of this workaround - because it doesn’t seem to work if you try to call code on a nonexistent file (in order to create said file and edit it) -

code() {
    if [ ! -e "$@" ]
    then
        touch "$@"
    fi
    open -b com.microsoft.VSCode "$@"
}

+1 on macOS Mojave 10.14.6

Same problem on macOS Catalina 10.15 Screen Shot 2019-10-15 at 11 54 45

Below script save as code command, work fine for me

#!/usr/bin/env bash

open -b com.microsoft.VSCode "$@"

Could the code script that ships with VSCode be updated to do something similar?

I’m seeing this on Mojave (yes I’ll update to Big Sur soon). I have disabled the “recent applications” area of my Dock so I only see it in the main area, which is for saved and running applications. It is triggered by running code --wait, e.g. for interactive git operations.

alias code=‘open -b com.microsoft.VSCode “$@”’

This workaround doesn’t work with the --wait option, nor does adding the -W flag to open.

Can also reproduce on Big Sur. Reproduction steps:

  • remove VSCode icon from taskbar
  • quit VSCode
  • run code . in the Terminal
  • run code . in the Terminal again
  • see two VSCode icons in the Terminal instead of one.

@yiminghe It works for me:

2020-11-23_12-52-17 (1)

What are you exact steps?

All the information pointing to “Show recent applications in Dock” being the issue seems to be very wrong to me. I do not, and never have, liked having that checked. Even without it, it still dupes up the VSCode icon on my dock when I type code . in the terminal. I have tried using “alt-click, options, Remove from Dock” on the original icon, and then “alt-click, options, Keep in Dock” on the new one. That will fix it for the current terminal session, however, opening a new terminal tab and typing code . gives me a brand new duplicate. I never get more than one extra though. I’m on Mojave 10.14.4.

I’d be much more interested in finding out why it is that macOS creates separate icons for Code and fix that problem at the root. Have you tried Atom? Does it have the same issue?

@fourcels That’s good, but you lose most command line powers (–install-extension, for example).

Really no idea why this duplicate icon happens. 🤔