DEV Community

sunah kim
sunah kim

Posted on Originally published at zenn.dev

Open Any Finder Folder in VS Code with One Keystroke (Automator Quick Action)

Dragging folders gets old fast

When you're browsing a project folder in Finder and think "I want this open in VS Code" — what do you do?

For a long time, I would launch VS Code first and then drag the folder onto the Dock icon or the window. Or open a terminal, cd into the folder, and run code .. Either way it's only a few seconds, but repeated many times a day it adds up. It feels especially tedious when you just want to peek at the contents.

With macOS's built-in Automator, you can create a "Quick Action" once, and from then on it's: select the folder in Finder → right-click (or press a shortcut key) → VS Code opens instantly. Setup takes five minutes. Here's the procedure, plus the one detail that matters.

Creating the Quick Action in Automator

1. Create a new Quick Action

Launch Automator.app and choose "Quick Action" as the new document type.

2. Configure how input is received

Change the settings at the top of the workflow as follows. If you get this wrong, the action won't appear in Finder's right-click menu at all:

  • "Workflow receives current" → folders
  • "in" → Finder.app

3. Add "Run Shell Script"

Drag "Run Shell Script" from the action list on the left into the workflow, and configure it:

  • Shell: /bin/zsh (bash works too)
  • Pass input: "as arguments" (if you leave the default "to stdin", "$@" will be empty)

The script itself is just this:

for f in "$@"; do
  open -a "Visual Studio Code" "$f"
done
Enter fullscreen mode Exit fullscreen mode

The loop is there so that selecting multiple folders opens each one in its own window.

4. Save

Press ⌘S and give it a name. I went with "Open in VS Code" — this name is exactly what shows up in the context menu.

Now you can right-click any folder in Finder → "Quick Actions" → "Open in VS Code".

Assigning a keyboard shortcut

If you want to skip even the right-click:

  1. System Settings → Keyboard → Keyboard Shortcuts
  2. Open "Services" → "Files and Folders" on the left
  3. Find your saved "Open in VS Code" action and assign a shortcut (I used ⌃⌥V)

Select a folder in Finder, press the key, and VS Code opens. Once you have this, there's no going back to dragging.

The key point: use open -a, not the code command

It's tempting to write the script as code "$f", but using open -a is the whole point of this setup. Two reasons:

1. You sidestep the PATH problem. The code command only exists after you run "Shell Command: Install 'code' command in PATH" from the VS Code command palette. Worse, Automator's shell runs without loading .zshrc, so your interactive shell's PATH settings don't apply. In other words, even if code works fine in your terminal, inside Automator it tends to fail with command not found. Meanwhile, open -a is a standard macOS command that works from anywhere as long as the application name is correct.

2. It's portable with zero setup. With open -a, the same Quick Action works on your teammates' Macs as long as VS Code is installed. No "please enable the code command first" prerequisite — a small but real win.

Note that the app name must match the official name in your Applications folder. If you use VS Code Insiders, it's "Visual Studio Code - Insiders". A mismatched name fails with an Unable to find application error.

Summary

  • Automator's Quick Actions let you go from a Finder right-click straight to VS Code
  • Input must be "folders" / "Finder.app", passed "as arguments" — get these wrong and nothing works
  • The script is open -a "Visual Studio Code" "$f"; unlike the code command, it needs no PATH setup
  • Assign a key in System Settings → Keyboard Shortcuts → Services to shrink it down to a single keystroke

This is the kind of setup you build once and use until you switch operating systems. If you're still dragging folders every time, it's worth the five-minute investment.

Reference

Top comments (0)