DEV Community

Moya Richards
Moya Richards

Posted on

macOS: Open Files and Folders in VS Code from Finder

You probably already know that you can open the current directory in Visual Studio Code from Terminal with:

code .
Enter fullscreen mode Exit fullscreen mode

That works well when you're already in Terminal.

But if you're browsing a project in Finder, opening Terminal, navigating to the same directory, and typing code . can feel like unnecessary work.

Instead, you can add Open in VS Code directly to Finder.

In this guide, I'll show you two ways to set it up:

  • Manually: create a macOS Quick Action with the Automator app.
  • Automatically: use a shell script to create the same Quick Action.

Both methods create a Finder action that opens selected files or folders in VS Code. The difference is that the manual method requires you to create and save the Quick Action yourself, while the shell script automates those same steps.

The manual method also shows you how to assign a keyboard shortcut, so you can open a selected file or folder in VS Code without using Finder's context menu.

You can still use code . whenever you're already working in Terminal and want to open the current directory in VS Code quickly.


Table of Contents


Option 1: Create the Quick Action Manually with the Automator App

The manual method creates a Finder action using macOS's built-in Automator app.

If you'd rather use macOS's built-in tools and avoid running an installer script, you can create a Quick Action with the Automator app.

The entire workflow only requires one shell command.

1. Open the Automator App

Start by opening the Automator app.

You can find it in the Applications folder or launch it from Terminal:

open -a Automator
Enter fullscreen mode Exit fullscreen mode

When Automator opens, choose:

New Document → Quick Action

At the top of the workflow, configure:

  • Workflow receives current: files or folders
  • in: Finder

This tells macOS to make the Quick Action available whenever you select files or folders in Finder.


2. Add the Shell Script

In the Automator app's Actions panel, search for:

Run Shell Script

Drag it into the workflow.

Configure the action with:

  • Shell: /bin/zsh
  • Pass input: as arguments

Automator adds a default shell script to the action.

Delete it and replace it with:

/usr/bin/open -b com.microsoft.VSCode "$@"
Enter fullscreen mode Exit fullscreen mode

That's the entire script.

It tells macOS to open the Finder selection with Visual Studio Code.


3. Save and Test the Quick Action

Save the workflow by choosing:

File → Save

Name it:

Open in VS Code

Now open Finder and test it.

  1. Select a file or folder.
  2. Right-click the selection.
  3. Choose Quick Actions → Open in VS Code.

VS Code should open the selected item.

Depending on your macOS version and configuration, Open in VS Code may appear under Services instead of Quick Actions.

The action also works when multiple Finder items are selected.


4. Add a Keyboard Shortcut

If you use the Quick Action frequently, you can assign it a keyboard shortcut.

Open:

System Settings → Keyboard → Keyboard Shortcuts → Services

Find the Files and Folders section, then locate:

Open in VS Code

Double-click the key combination none shown next to the service to record a custom keyboard shortcut. After double-clicking, press the desired shortcut keys on your keyboard, such as: Shift + Command + V.

⇧⌘V

After that, your workflow becomes:

Select a file or folder in Finder
        ↓
Press ⇧⌘V
        ↓
Open in VS Code
Enter fullscreen mode Exit fullscreen mode

Now you can jump directly from Finder to VS Code without opening the context menu.


Option 2: Install the Automator Quick Action Automatically with a Shell Script

Use this shell script if you want to automate the setup or repeat it on another Mac.

The installer creates the same Quick Action described in the manual method and provides commands to check its status or remove it later.

Your workflow is still:

Select a file or folder in Finder
  ↓
Quick Actions → Open in VS Code
Enter fullscreen mode Exit fullscreen mode

Instead of setting up the workflow yourself, the script creates the Quick Action, adds the shell command, configures Finder as the input location, and registers the workflow with macOS.

The installer is available in my GitHub repository:

Open Files and Folders in VS Code from Finder

The installer file is:

install-open-in-vscode-plugin.sh
Enter fullscreen mode Exit fullscreen mode

Download the Installer

Clone the repository:

git clone https://github.com/moyarich/Open-Files-and-Folders-in-VS-Code-from-Finder.git
Enter fullscreen mode Exit fullscreen mode

Then enter the project directory:

cd Open-Files-and-Folders-in-VS-Code-from-Finder
Enter fullscreen mode Exit fullscreen mode

You can also download the install-open-in-vscode-plugin.sh file directly from the repository if you don't want to clone the entire project.

Install

First, make the installer executable:

chmod +x ./install-open-in-vscode-plugin.sh
Enter fullscreen mode Exit fullscreen mode

Then run:

zsh ./install-open-in-vscode-plugin.sh install
Enter fullscreen mode Exit fullscreen mode

The script creates the Automator Quick Action, adds the VS Code command, configures it to receive files and folders from Finder, and registers the workflow with macOS.

After the installation finishes, try right-clicking a file or folder in Finder.

You should see:

Open in VS Code

Check the Installation Status

The installer also includes a status command:

zsh ./install-open-in-vscode-plugin.sh status
Enter fullscreen mode Exit fullscreen mode

This checks whether the Automator Quick Action has been created and registered.

Uninstall

To remove the automatically installed Quick Action:

zsh ./install-open-in-vscode-plugin.sh uninstall
Enter fullscreen mode Exit fullscreen mode

This removes the Automator workflow from your system.


How the Automator Command Works

The entire Automator Quick Action is powered by one command:

/usr/bin/open -b com.microsoft.VSCode "$@"
Enter fullscreen mode Exit fullscreen mode

When you create the Quick Action manually, you add this command yourself. When you use the installer, the script adds the same command to the Automator workflow automatically.

There are three important parts:

/usr/bin/open  -b com.microsoft.VSCode  "$@"
│              │                        │
│              │                        └─ Finder selections
│              └─ Application to use
└─ macOS open command
Enter fullscreen mode Exit fullscreen mode

Let's look at each one.

/usr/bin/open

open is a built-in macOS command for opening files, directories, URLs, and applications.

For example:

open .
Enter fullscreen mode Exit fullscreen mode

opens the current directory in Finder.

You can also use it to open a specific file:

open README.md
Enter fullscreen mode Exit fullscreen mode

or launch an application:

open -a "Visual Studio Code"
Enter fullscreen mode Exit fullscreen mode

In the Automator workflow, we're using the full executable path:

/usr/bin/open
Enter fullscreen mode Exit fullscreen mode

This ensures that the Automator app calls the macOS open command directly instead of depending on the shell's PATH.


-b com.microsoft.VSCode

The next part is:

-b com.microsoft.VSCode
Enter fullscreen mode Exit fullscreen mode

The -b option tells open which application should handle the item by specifying the application's bundle identifier.

Visual Studio Code's bundle identifier is:

com.microsoft.VSCode
Enter fullscreen mode Exit fullscreen mode

So this:

open -b com.microsoft.VSCode
Enter fullscreen mode Exit fullscreen mode

essentially means:

Open this with Visual Studio Code.

Using the bundle identifier is useful because the command doesn't have to depend on the exact location of Visual Studio Code.app.


Passing Finder Selections

The final part is:

"$@"
Enter fullscreen mode Exit fullscreen mode

This represents the arguments passed to the shell script.

Earlier, we configured the Automator app to:

Pass input: as arguments

When you select files or folders in Finder, Automator passes those paths to the script as command-line arguments.

For example, imagine selecting these two folders:

~/Projects/project-one
~/Projects/project-two
Enter fullscreen mode Exit fullscreen mode

Conceptually, Automator ends up running something similar to:

/usr/bin/open -b com.microsoft.VSCode \
  "/Users/your-name/Projects/project-one" \
  "/Users/your-name/Projects/project-two"
Enter fullscreen mode Exit fullscreen mode

You don't have to construct that command yourself.

"$@" forwards all of the arguments Automator received.

The quotes are important.

Consider a folder named:

My React Project
Enter fullscreen mode Exit fullscreen mode

Without proper quoting, a shell could interpret that as three separate values:

My
React
Project
Enter fullscreen mode Exit fullscreen mode

Using:

"$@"
Enter fullscreen mode Exit fullscreen mode

preserves every selected path as its own argument.

That's why the Quick Action works with:

  • one file
  • one folder
  • multiple files
  • multiple folders
  • files and folders whose names contain spaces

Keep Using code . in Terminal

If you're already in Terminal:

code .
Enter fullscreen mode Exit fullscreen mode

is usually the fastest option.

If you're already browsing files in Finder, the Quick Action saves you from opening Terminal, navigating back to the same directory, and running another command.

It's a small macOS customization, but if you regularly move between Finder, Terminal, and Visual Studio Code, it removes a repetitive step from your development workflow.

Top comments (0)