The best way to go about this is to use Automator which is a built in application in macOS.
- Open the Automator app.
- Choose
New Document->Quick Action. - Set
Workflow receives current:foldersinFinder.app. - Add the
Run Shell Script action. - Select
bashas yourshellandpass inputas arguments. - In the script box, enter:
/usr/local/bin/code -n "$@" - Save it as
Open in VS Code. (Don’t close Automator just yet) - Immediately into effect, when you right‑click a folder in Finder, you’ll see under
Quick Actions->Open in VS Code. - Optionally, you can add the VS Code icon too; for Image, select
Choose...-> navigate toApplication-> look forVisual Studio Codeand select it. The application’s image will be pulled in. - You may save the script and close Automator.
By default you’ll find the script saved to ~/Library/Services/ folder as Open in VS Code.workflow. It’s a compressed file consisting of XML and static resource files which you can explore by dragging and dropping into VS Code!
Enjoy!