Open folder in VSCode and in other applications on macOS

post thumb
macOS configuration

Read this post if you are using macOS operating system and want to open a folder in the Finder directly in Visual Studio Code, pyCharm, or another application. This feature is especially missed by those who migrated from Windows to macOS. I use it every day and recommend you test it as well.

Table of contents

| What is needed to configure?

  1. Shortcuts 1 application or Automator 2 application to configure Quick Action and make it visible in the context menu as an option, e.g., “Open in…”.
  2. Bundle Identifier 3 of an application in which you want to open a folder from the Finder (optional).
  3. Terminal application to find application Bundle Identifier (optional).

To set up a Quick Action, you can use one of two apps created by Apple, Shortcuts or Automator. In each of them, you can set up a Quick Action in two different ways. In the simplest solution, you select the target application from a list. In a slightly more advanced solution, you use a shell script. This allows you to open several folders simultaneously in several windows of the target application. 4

| Quick Action setup in Shortcuts application

The Shortcuts application allows you to speed up the execution of tasks in macOS, iOS, and iPadOS. Nothing is lost if your macOS version is older than macOS Monterey and you don’t have the Shortcuts app. You can use the Automator application. Go to a quick Action setup in Automator application section.

| Quick Action in Shortcuts application

  1. Open the Shortcuts application by pressing cmd⌘ space, to run Spotlight, type-in: “Shortcuts”, and press Enter⏎, to confirm of opening the selected application.
  2. Select Quick Actions in section My Shortcuts in the left sidebar.
  3. Click on the icon with plus sign (+) on the top of the window to add New Shortcut or go to File > New shortcut (or press cmd⌘ N).
Creation of new shortcut in the Shortcut application.

Creation of new shortcut in the Shortcut application.

  1. Change Receive Any option from Any to Receive Files and Folders.
  2. Search for Open file action in the search field of Action Library on the right side of the window and add this action to your workflow by double-clicking it or dragging it to the left side of the window.
  3. Change Open Shortcut Input in option in Open file action from Default app to Visual Studio Code.
  4. Go to the top part of the window and set the name, e.g., Open in Visual Studio Code. You can also change the icon and icon’s color for Quick Action.
  5. Go to Shortcut Details in the right sidebar and make sure that you have marked Use as Quick Action option and Finder option below to have this Quick Action visible in the context menu in Finder.
Shortcuts application window showing Open file Quick Action which lets create action Open in Visual Studio Code

New shortcut configuration in Shortcut application using Open file Quick Action.

  1. Next, go to Finder, to test Quick Action.
  2. Click RMB (right mouse button) on selected folder or file.
  3. Choose Quick Actions > Open in Visual Studio Code.
Finder application window showing Quick Action which lets to open folder in Visual Studio Code

Using new shortcut in Finder application.

If you have path bar enabled (alt⌥cmd⌘ P) in Finder and want to use this Quick Action from path bar, click RMB (right mouse button) on folder or file in path bar and choose from the context menu Services > Open in Visual Studio Code.

| Quick Action in Shortcuts application for advanced

If you want to open, e.g., two folders at the same time in two separate Visual Studio Code windows use Run Shell Script Quick Action.

  1. Open the Shortcuts application by pressing cmd⌘ space, to run Spotlight, type-in: “Shortcuts”, and press Enter⏎, to confirm of opening the selected application.
  2. Select Quick Actions in section My Shortcuts in the left sidebar.
  3. Click on the icon with plus sign (+) on the top of the window to add New Shortcut or go to File > New shortcut (or press cmd⌘ N).
  4. Change Receive Any option from Any to Receive Files and Folders.
  5. Search for Run Shell Script action in the search field of Action Library on the right side of the window and add this action to your workflow by double-clicking it or dragging it to the left side of the window.

If you see notification This action cannot be run because scripting actions are disabled. Click Open Preferences button and mark first option Allow Running Scripts. Then go back to creating a Quick Action.

  1. Copy and paste the following code to Run Shell Script action:
for f in "$@"
do
    open -n -b "com.microsoft.VSCode" --args "$f"
done
  1. Change Input option in Run Shell Script action to Type: Folder oraz Get: File Path.
  2. Change Pass Input option in Run Shell Script action from to stdin to as arguments.
  3. Go to the top part of the window and set the name, e.g., Open in Visual Studio Code. You can also change the icon and icon’s color for Quick Action.
  4. Go to Shortcut Details in the right sidebar and make sure that you have marked Use as Quick Action option and Finder option below to have this Quick Action visible in the context menu in Finder.
Shortcuts application window showing Run Shell Script Quick Action which lets create action Open in Visual Studio Code

New shortcut configuration in Shortcut application using Run Shell Script Quick Action.

  1. Next, go to Finder, to test Quick Action.
  2. Click RMB (right mouse button) on selected folder or file.
  3. Choose Quick Actions > Open in Visual Studio Code.

| Quick Action setup in Automator application

The Automator application allows you to speed up the execution of tasks in macOS. If your macOS version is at least macOS Monterey I recommend you use the Shortcuts app, which you can use in a similar way on iOS and iPadOS. Go to a quick Action setup in Shortcuts application section.

| Quick Action in Automator application

  1. Open Automator by pressing cmd⌘ space to run Spotlight, type-in: “Automator”, and press Enter⏎ to confirm opening.
  2. Go to File > New (or press cmd⌘ N).
  3. Choose a type for your document: Quick Action.
  4. Change Workflow Receives current option from ? to files or folders
  5. Change in option from ? to Finder.app.
  6. You can also change icon for your Quick Action which you will see in context menu.
  7. Search for a Open Finder Items action in the search bar on the left side of the window and add this action to your workflow by double-clicking it or dragging it to the right side of the window.
  8. Change Open with option in Open Finder Items action from Default Application to Visual Studio Code.
  9. Go to File > Save (or press cmd⌘ S) to save Quick Action as, e.g., Open in Visual Studio Code.
Automator application window showing Open Finder Items Quick Action which lets create action Open in Visual Studio Code

New shortcut configuration in Automator application using Open Finder Items Quick Action.

  1. Now, to test it, go to Finder.
  2. Click RMB (right mouse button) on folder or file.
  3. Choose from the context menu Quick Actions > Open in Visual Studio Code.

If you have path bar enabled (alt⌥cmd⌘ P) in Finder and want to use this Quick Action from path bar, click RMB (right mouse button) on folder or file in path bar and choose from the context menu Services > Open in Visual Studio Code.

| Quick Action in Automator application for advanced

  1. Open Automator by pressing cmd⌘ space to run Spotlight, type-in: “Automator”, and press Enter⏎ to confirm opening.
  2. Go to File > New (or press cmd⌘ N).
  3. Choose a type for your document: Quick Action.
  4. Change Workflow Receives current option from ? to files or folders
  5. Change in option from ? to Finder.app.
  6. You can also change icon for your Quick Action which you will see in context menu.
  7. Search for a Run Shell Script action in the search bar on the left side of the window and add this action to your workflow by double-clicking it or dragging it to the right side of the window.
  8. Change option Pass input in action Run Shell Script from to stdin to as arguments.
  9. Copy and paste the following code to action Run Shell Script:
for f in "$@"
do
    open -n -b "com.microsoft.VSCode" --args "$f"
done
  1. Go to File > Save (or press cmd⌘ S) to save Quick Action as, e.g., Open in Visual Studio Code.
Automator application window showing Open Run Shell Script Quick Action which lets create action Open in Visual Studio Code

New shortcut configuration in Automator application using Run Shell Script Quick Action.

  1. Now, to test it, go to Finder.
  2. Click RMB (right mouse button) on folder or file.
  3. Choose from the context menu Quick Actions > Open in Visual Studio Code.

If you have path bar enabled (alt⌥cmd⌘ P) in Finder and want to use this Quick Action from path bar, click RMB (right mouse button) on folder or file in path bar and choose from the context menu Services > Open in Visual Studio Code.

All your Quick Actions are saved in location /Users/$USER/Library/Services

| Find Bundle Identifier of application

If you want to create a Quick Action for other applications using a shell script, you must first find the application’s Bundle Identifier. You can use Terminal or Finder to do this. In the following example, you will learn how to do this for PyCharm application. PyCharm is an integrated development environment (IDE) that I use almost daily (not only for python programming).

| Find Bundle Identifier of application using Terminal

  1. Hover on PyCharm application icon in Dock (icon bar at the bottom of the screen) to get the exact name. In my case, it’s PyCharm CE.
  2. Go to Terminal application and type in:
osascript -e 'id of app "PyCharm CE"'

as a result you should receive:

com.jetbrains.pycharm.ce

| Find Bundle Identifier of application using Finder

  1. Click RMB (right mouse button) on PyCharm icon in Dock.
  2. Choose in context menu Options > Show in Finder.
  3. Click RMB (right mouse button) on PyCharm icon in Finder.
  4. Choose in context menu Show Package Contents.
  5. Open Contents folder.
  6. Open info.plist text file, e.g., in TextEdit or any other text editor.
  7. Find the CFBundleIdentifier key and copy the text between the <string> </string> tags (check the example below).
<key>CFBundleIdentifier</key>
<string>com.jetbrains.pycharm.ce</string>

  1. Read more about Shortcuts in the Apple’s Shortcuts User Guide↩︎

  2. Read more about Automator in the Apple’s Automator User Guide↩︎

  3. Read more about CFBundleIdentifier (Bundle identifier) in the Apple’s Bundle Programming Guide↩︎

  4. Open in Visual Studio Code Quick Action based on jnovack post @ stackoverflow.com, CC BY-SA 4.0 ↩︎