macosvisual-studio-codefinder

Open a folder in vscode through Finder in macOS?


On my windows pc, I would just double click a folder and click "Open in VS Code" to a open a folder, which saved time for me when looking through lots of code online. With Mac, however, I do not have this option. I have to directly open vscode and click "Open" to open a new folder. How do I directly open a file in vscode through finder in macOS?


Solution

  • 2023 Update - Use Native Method

    1. Open the Command Palette (Cmd+Shift+P) and type shell command to find the Shell Command: Install 'code' command in PATH command.

    Command Palette

    1. Restart all terminal sessions for the new $PATH value to take effect.

    You'll be able to type code . in any folder to start editing files in that folder.


    If you want to do it in Finder, you can write an Automator script to do it (it's easier than it sounds, AND shows you the power of the OS).

    1. Launch Automator

    2. Create New Document

    3. Create a new Quick Action Select "Quick Action"

    4. Add the Action... (New Method - 10.13+)

      • Workflow receives current files or folders from Finder.
      • Add a new "Open Finder Items" action to the workflow. (drag the "Open Finder Items" object, highlighted in the screenshot, to the empty window on the right)
      • Select "Visual Studio Code" from the list.

    1. Add the Action... (Old Method)

      • Workflow receives current files or folders from Finder.
      • Add a new Run Shell Script action to the workflow. (drag the "Run Shell Script" object, highlighted in the screenshot, to the empty window on the right)
    2. Configure the Workflow (Old Method)

      • Set the Pass Input to be as arguments
      • Paste the following in the input box:
      open -n -b "com.microsoft.VSCode" --args "$*" 
      

      Screenshot of Workflow

    3. Save the action using a name like Open in Visual Studio Code.

    You may now right-click on the folder and find your newly created task under Quick Actions.

    enter image description here